import { useEffect , useState } from 'react' ; param { T } value param timeout returns { Readonly < T > } see https export function useDebounce < T > ( value , timeout ) { const [ state , setState ] = useState ( value ) ; useEffect ( ( ) => { const tick = setTimeout ( ( ) => setState ( value ) , timeout ) ; return ( ) => clearTimeout ( tick ) ; } , [ value , timeout ] ) ; if ( timeout <= 0 ) return value ; return state ; }