// A simple debounce function export const debounce = any>(func: F, waitFor: number) => { let timeout: ReturnType | null = null; const debounced = (...args: Parameters) => { if (timeout !== null) { clearTimeout(timeout); timeout = null; } timeout = setTimeout(() => func(...args), waitFor); }; const cancel = () => { if (timeout !== null) { clearTimeout(timeout); timeout = null; } }; return [debounced, cancel] as [(...args: Parameters) => void, () => void]; };