Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/wojtekmaj/react-hooks. A collection of React Hooks.
hooks react react-hooks
Something went wrong. Try again.
510 B · 17 lines
TypeScript
at main
123456789101112131415161718import { useEffect } from 'react';
/** * Runs a given function every n milliseconds. * * @param {Function} fn Function to run. WARNING! If you define the function in component body, * make sure to memoize it. * @param {number} delay Interval between function runs (in ms) * @returns {void} */export default function useSetInterval(fn: () => void, delay: number): void { useEffect(() => { const interval = setInterval(fn, delay);
return () => clearInterval(interval); }, [fn, delay]);}