function debounce void>(func: T, wait: number): (...args: Parameters) => void { let timeout: number | null; return (...args: Parameters) => { if (timeout) { clearTimeout(timeout); } timeout = setTimeout(() => { func(...args); }, wait); }; } /** * function handleSearch(query: string) { * console.log('Searching for:', query); * } * * // Create a debounced version of the function with a 300ms delay * const debouncedSearch = useRef(debounce(handleSearch, 300)); * * // Use the debounced function in an event handler * debouncedSearch(target.value); */ export default debounce