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