streamich / react-use

React Hooks — 👍
http://streamich.github.io/react-use
The Unlicense
42k stars 3.16k forks source link

useCallback to wrap useHash mount and unmount lifecycles fix#2594 #2595

Closed asasvirtuais closed 2 months ago

asasvirtuais commented 2 months ago

Description

useCallback to wrap useHash mount and unmount lifecycles

useLifecycles(
  useCallback( () => on(window, 'hashchange', onHashChange), []),
  useCallback( () => off(window, 'hashchange', onHashChange), [])
);

Type of change

Checklist

asasvirtuais commented 2 months ago

The rabbit hole is deeper than I imagined it'd be. Seems like useEffect would be the right approach to solve this issue with Next.js, but it would completely change the way this works on React only apps.