Check if Thumbnail is still mounted before confirming its image loaded

This commit is contained in:
Alex Liebowitz 2017-01-04 15:46:20 -05:00
parent a6b7b3de5a
commit c3e08809c2

View file

@ -120,6 +120,7 @@ export let Address = React.createClass({
export let Thumbnail = React.createClass({
_defaultImageUri: '/img/default-thumb.svg',
_maxLoadTime: 10000,
_isMounted: false,
propTypes: {
src: React.PropTypes.string.isRequired,
@ -137,14 +138,18 @@ export let Thumbnail = React.createClass({
};
},
componentDidMount: function() {
this._isMounted = true;
setTimeout(() => {
if (!this.refs.img.complete) {
if (this._isMounted && !this.refs.img.complete) {
this.setState({
imageUri: this._defaultImageUri,
});
}
}, this._maxLoadTime);
},
componentWillUnmount: function() {
this._isMounted = false;
},
render: function() {
return <img ref="img" onError={this.handleError} {... this.props} src={this.state.imageUri} />
},