UNPKG

ah-resque-ui

Version:

A resque administration website for actionhero

28 lines (22 loc) 554 B
import { useEffect, useRef } from "react"; function useInterval(callback, delay) { const savedCallback = useRef(); // Remember the latest callback. useEffect(() => { savedCallback.current = callback; }, [callback]); // Set up the interval. useEffect(() => { function tick() { if (savedCallback) { //@ts-ignore savedCallback.current(); } } if (delay !== null) { const id = setInterval(tick, delay); return () => clearInterval(id); } }, [delay]); } export default useInterval;