Skip to content

Commit cbd9c0a

Browse files
committed
Trigger afterLoad on componentDidUpdate instead of setState callback
1 parent b713204 commit cbd9c0a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/components/LazyLoadImage.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ class LazyLoadImage extends React.Component {
7676
};
7777
}
7878

79-
componentDidUpdate() {
79+
componentDidUpdate(prevProps, prevState) {
80+
if (!prevState.visible && this.state.visible) {
81+
this.props.afterLoad();
82+
}
83+
8084
if (this.placeholder) {
8185
const boundingBox = this.getPlaceholderBoundingBox();
8286

@@ -102,7 +106,7 @@ class LazyLoadImage extends React.Component {
102106

103107
this.setState({
104108
visible: true
105-
}, this.props.afterLoad);
109+
});
106110
}
107111

108112
isImageInViewport(scrollPosition) {

0 commit comments

Comments
 (0)