import { useState , useEffect } from 'react' ; export function useDebounce < T > ( value , delay ) { const [ debouncedValue , setDebouncedValue ] = useState ( value ) ; useEffect ( ( ) => { const handler = window . setTimeout ( ( ) => { setDebouncedValue ( value ) ; } , delay ) ; return ( ) => window . clearTimeout ( handler ) ; } , [ value , delay ] ) ; return debouncedValue ; }