make LazyImage promise cancellable (otheriwse errors in the log)

This commit is contained in:
or-else
2021-09-27 15:56:11 -07:00
parent 2e589bef0c
commit a223d910c1
9 changed files with 362 additions and 285 deletions
+6
View File
@@ -16,11 +16,17 @@ export default class LazyImage extends React.PureComponent {
}
componentDidMount() {
// whenDone is a wrapper around an actual promise to be able to cancel it.
this.props.whenDone
.promise
.then(data => this.setState({src: data.src, style: {...this.state.style, padding: 0}}))
.catch(() => this.setState({src: 'img/broken_image.png'}));
}
componentWillUnmount() {
this.props.whenDone.cancel();
}
componentDidUpdate(prevProps) {
if (prevProps.whenDone != this.props.whenDone) {
this.setState({src: 'img/placeholder.png', style: {...this.state.style, padding: '4px'}});