/** * Hook that creates a setInterval that automatically cleans up on unmount. * * Provides a declarative way to use intervals in React components with proper * cleanup and the ability to pause/resume by passing null as the delay. * * @param callback - The function to execute on each interval tick * @param delay - The delay in milliseconds between executions, or null to pause the interval * * @example * ```tsx * function Timer() { * const [count, setCount] = useState(0); * const [isRunning, setIsRunning] = useState(true); * * // Increment count every second when running * useInterval(() => { * setCount(count => count + 1); * }, isRunning ? 1000 : null); * * return ( *
Count: {count}
* *