function debounce<T extends (...args: any[]) => void>(func: T, wait: number): (...args: Parameters<T>) => void {
	let timeout: number | null;
	return (...args: Parameters<T>) => {
		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
