Skip to content

Commit

Permalink
Merge pull request #217 from lkazberova/master
Browse files Browse the repository at this point in the history
Fix #216 Cannot read property 'complete' of undefined
  • Loading branch information
neptunian committed Jul 18, 2018
2 parents 0ad0ba4 + 7c2f640 commit 14e8adc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Lightbox.js
Expand Up @@ -86,8 +86,8 @@ class Lightbox extends Component {

// preload current image
if (this.props.currentImage !== nextProps.currentImage || !this.props.isOpen && nextProps.isOpen) {
const img = this.preloadImage(nextProps.currentImage, this.handleImageLoaded);
this.setState({ imageLoaded: img.complete });
const img = this.preloadImageData(nextProps.images[nextProps.currentImage], this.handleImageLoaded);
if (img) this.setState({ imageLoaded: img.complete });
}

// add/remove event listeners
Expand All @@ -109,10 +109,10 @@ class Lightbox extends Component {
// ==============================

preloadImage (idx, onload) {
const data = this.props.images[idx];

return this.preloadImageData(this.props.images[idx], onload);
}
preloadImageData (data, onload) {
if (!data) return;

const img = new Image();
const sourceSet = normalizeSourceSet(data);

Expand Down

0 comments on commit 14e8adc

Please sign in to comment.