I had higher order component in react like this:
export default function (InnerComponent) {
class InfiniteScrolling extends React.Component {
co
I know it's a little bit late, but I just encounter this issue and wanted to share with you my solution, looking forward to any feedback. this solution includes react hooks. I hope you like
// Declare a static listener.
const eventListeners = useRef();
// now let's create our scroll Handler
const scrollHandler = useCallback(() => {...},[]);
useEffect(() => {
// Here will be removing the static listener and then updated it for
// our new one since the first time will be empty it won't do anything.
window.removeEventListener('scroll', eventListeners.current, true);
// Then will set our current scroll handler to our static listener
eventListeners.current = scrollHandler;
// Here will be adding the static listener so we can keep the reference
// and remove it later on
window.addEventListener('scroll', eventListeners.current, true);
},[scrollHandler]);