everything seems to work as expected

This commit is contained in:
or-else
2021-09-18 15:02:27 -07:00
19 changed files with 599 additions and 541 deletions
+13 -3
View File
@@ -8,18 +8,28 @@ export default class LazyImage extends React.PureComponent {
this.state = {
src: 'img/placeholder.png',
style: this.props.style,
style: Object.assign({padding: '4px'}, this.props.style),
className: this.props.className,
loading: 'lazy',
alt: this.props.alt,
onClick: this.props.onClick,
};
}
componentDidMount() {
this.props.whenDone
.then(data => this.setState({src: data.src}))
.then(data => this.setState({src: data.src, style: {...this.state.style, padding: 0}}))
.catch(() => this.setState({src: 'img/broken_image.png'}));
}
componentDidUpdate(prevProps) {
if (prevProps.whenDone != this.props.whenDone) {
this.setState({src: 'img/placeholder.png', style: {...this.state.style, padding: '4px'}});
this.props.whenDone
.then(data => this.setState({src: data.src, style: {...this.state.style, padding: 0}}))
.catch(() => this.setState({src: 'img/broken_image.png'}));
}
}
render() {
return React.createElement('img', this.state);
}