import { useEffect , useRef } from 'react' ; export function usePoller ( fn , extraWatch ? , delay = 2000 ) { let savedCallback = useRef < VoidFunction > ( ) ; useEffect ( function ( ) { fn ( ) ; } , extraWatch ?? [ ] ) ; useEffect ( function ( ) { savedCallback . current = fn ; } , [ fn ] ) ; useEffect ( function ( ) { function tick ( ) { if ( savedCallback . current ) savedCallback . current ( ) ; } var id_1 = setInterval ( tick , delay ) ; return function ( ) { return clearInterval ( id_1 ) ; } ; } , [ delay ] ) ; }