Skip to content
This repository was archived by the owner on Jan 19, 2023. It is now read-only.

Commit 50a87fe

Browse files
author
Satyanarayan Dash
committed
property added to handle error
1 parent 84ba6c0 commit 50a87fe

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ nextSrcThumbnail | string | | | Thumbnail image url c
9292
onCloseRequest | func | | yes | Close window event. Should change the parent state such that the lightbox is not rendered
9393
onMovePrevRequest | func | empty function | | Move to previous image event. Should change the parent state such that props.prevSrc becomes props.mainSrc, props.mainSrc becomes props.nextSrc, etc.
9494
onMoveNextRequest | func | empty function | | Move to next image event. Should change the parent state such that props.nextSrc becomes props.mainSrc, props.mainSrc becomes props.prevSrc, etc.
95+
onLoadError | func | error object | | Will listen to the error if image is not loading
9596
discourageDownloads | bool | `false` | | Enable download discouragement (prevents [right-click -> Save Image As...])
9697
animationDisabled | bool | `false` | | Disable all animation
9798
animationOnKeyInput | bool | `false` | | Disable animation on actions performed with keyboard shortcuts

src/react-image-lightbox.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,8 @@ class ReactImageLightbox extends Component {
717717
const that = this;
718718
const inMemoryImage = new Image();
719719

720-
inMemoryImage.onerror = function onError() {
720+
inMemoryImage.onerror = () => {
721+
this.props.onLoadError(new Error('image load error'));
721722
callback('image load error');
722723
};
723724

@@ -1236,6 +1237,9 @@ ReactImageLightbox.propTypes = {
12361237
// props.mainSrc becomes props.prevSrc, etc.
12371238
onMoveNextRequest: PropTypes.func,
12381239

1240+
//Listener if any error occurs while loading the image
1241+
onLoadError: PropTypes.func,
1242+
12391243
//-----------------------------
12401244
// Download discouragement settings
12411245
//-----------------------------
@@ -1305,6 +1309,7 @@ ReactImageLightbox.propTypes = {
13051309
ReactImageLightbox.defaultProps = {
13061310
onMovePrevRequest: () => {},
13071311
onMoveNextRequest: () => {},
1312+
onLoadError: () => {},
13081313

13091314
discourageDownloads: false,
13101315

0 commit comments

Comments
 (0)