React useInterval Hook: setInterval Without Stale Closures (2026)
The React useInterval hook solves the stale closure issue with React's setInterval function. It keeps the latest callback in a ref and never restarts the timer due to component re-renders. This makes it easier to create a timer that reads the current state without needing a functional updater. To use it, install @reactuses/core and import the useInterval hook. The signature is useInterval(callback, delay, options?).