import { useState , useEffect , useCallback } from 'react' ; return { Object } export default ( ) => { const [ timeouts , setTimeouts ] = useState < number [ ] > ( [ ] ) ; useEffect ( ( ) => ( ) => { timeouts . forEach ( timeoutId => clearTimeout ( timeoutId ) ) ; } , [ timeouts ] ) ; const addTimeout = useCallback ( timeoutId => setTimeouts ( timeouts => [ ... timeouts , timeoutId ] ) , [ setTimeouts ] ) ; return { addTimeout } ; } ;