react-lazy-load icon indicating copy to clipboard operation
react-lazy-load copied to clipboard

shouldComponentUpdate returns true when the item is visible

Open MatanBobi opened this issue 8 years ago • 1 comments
trafficstars

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!

MatanBobi avatar Jun 07 '17 10:06 MatanBobi

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.

sfrieson-tm avatar Jul 21 '17 21:07 sfrieson-tm