import * as React from 'react' ; export const useTimeout = ( callback , delay ) => { if ( delay === 0 ) return ; const savedCallback = React . useRef ( ) ; React . useEffect ( ( ) => { savedCallback . current = callback ; } , [ callback ] ) ; React . useEffect ( ( ) => { function tick ( ) { if ( savedCallback ) { savedCallback . current ( ) ; } } if ( delay !== null ) { const id = setTimeout ( tick , delay ) ; return ( ) => clearTimeout ( id ) ; } } , [ delay ] ) ; } ;