react-use icon indicating copy to clipboard operation
react-use copied to clipboard

fix(useScrolling): clear timeout on unmount to prevent memory leak

Open selvaganapathycoder opened this issue 9 months ago • 0 comments

Summary

The useEffect cleanup function in useScrolling was not clearing the scrollingTimeout. This could lead to:

  • A memory leak from the retained timeout reference
  • A setState call on an unmounted component, causing a React warning

Changes

Added clearTimeout(scrollingTimeout) to the useEffect cleanup/return function so that the timeout is properly cleared when the component unmounts or the effect re-runs.

Before

return () => {
  if (ref.current) {
    off(ref.current, 'scroll', handleScroll, false);
  }
};    

after


return () => {
  clearTimeout(scrollingTimeout);
  if (ref.current) {
    off(ref.current, 'scroll', handleScroll, false);
  }
};

selvaganapathycoder avatar Feb 20 '26 13:02 selvaganapathycoder