import { useEffect , useRef } from 'react' ; export function useInterval ( callback , delay ) { const savedCallback = useRef < Function > ( callback ) ; useEffect ( ( ) => { savedCallback . current = callback ; } , [ callback ] ) ; useEffect ( ( ) => { function tick ( ) { savedCallback . current ( ) ; } if ( delay !== null ) { let id = setTimeout ( tick , delay ) ; return ( ) => clearTimeout ( id ) ; } } , [ delay ] ) ; }