import { useCallback , useRef } from "react" ; param func param delay param deps returns export default function useDebounce < T extends ( ... args : any [ ] ) => any > ( func , delay , deps = [ ] ) { const timer = useRef < number > ( ) ; const cancel = useCallback ( ( ) => { if ( timer . current ) { clearTimeout ( timer . current ) ; } } , [ ] ) ; const run = useCallback ( ( ... args ) => { cancel ( ) ; timer . current = window . setTimeout ( ( ) => { func ( ... args ) ; } , delay ) ; } , deps ) ; return run as T ; }