react-infinite-scroll-component
react-infinite-scroll-component copied to clipboard
Change in scrollableTarget not being tracked
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).
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 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).
Hey @ankeetmaini , I am interested in this issue.. If nobody is working on it, I would like to work on this..