import { useRef, useCallback } from 'react'; export function useDebounce any>( func: T, delay: number ): (...args: Parameters) => void { const timeoutRef = useRef(undefined); return useCallback( (...args: Parameters) => { if (timeoutRef.current) { clearTimeout(timeoutRef.current); } timeoutRef.current = setTimeout(() => { func(...args); }, delay); }, [func, delay] ); }