react-lazy-load
react-lazy-load copied to clipboard
shouldComponentUpdate returns true when the item is visible
Hey there! Im trying to understand whats the reason for the shouldcomponentupdate logic that you are applying.
shouldComponentUpdate(_nextProps, nextState) {
return nextState.visible;
}
If the current state is visible and the next one is also visible then why should i update the component? i would think that the wanted behavior should be:
shouldComponentUpdate(_nextProps, nextState) {
return !this.state.visible && nextState.visible;
}
What am i missing here? Thanks!
I'm inclined to agree. It isn't quite as simple as !this.state.visible && nextState.visible since props could have changed including props.children aka whatever is being lazy loaded. Adding a shallow equal of the props should work since all the props are primitives except props.children, leaving it up to the developer using the package to put in a component that will only cause the update when necessary.