react-infinite-scroll-component icon indicating copy to clipboard operation
react-infinite-scroll-component copied to clipboard

Change in scrollableTarget not being tracked

Open E-Mud opened this issue 6 years ago • 3 comments

Currently, InfiniteScroll adds the scroll listeners only when mounting. That means that if the scroll target (whether it's specified or default to window) changes, the component won't request a new page load if there's some scroll in the new target.

I guess the solution is to check in componentWillReceiveProps if there's some change in target, and if it's the case, remove the current listeners and re-add them (as it's done now on mounting).

E-Mud avatar Feb 05 '19 14:02 E-Mud

Or you can simply change the key in userland code ;)

class UseInfinite extends Component {
  render() {
    return (
      <InfiniteScroll
          key={'deterministic-key-based-on-your-scroll-listeners'}
          ...rest of the props
      />
    )
  }
}

This way the component will mount/unmount and attach proper listeners. Thoughts @E-Mud ?

ankeetmaini avatar Feb 06 '19 09:02 ankeetmaini

@ankeetmaini That's actually what we ended up doing and it works. I opened the issue because it felt more like a hack than a proper solution.

Although I think that, if attaching finally is left as it is, then maybe it should at least be documented (along with the proposed solution of using key).

E-Mud avatar Feb 06 '19 11:02 E-Mud

Hey @ankeetmaini , I am interested in this issue.. If nobody is working on it, I would like to work on this..

akashpatil14298 avatar Jul 29 '21 10:07 akashpatil14298