Files
b725b823-ee10-4181-9aa1-a7f…/src/utils/debounce.ts
2026-01-04 17:43:57 +00:00

15 lines
349 B
TypeScript

export function debounce<T extends (...args: unknown[]) => void>(
func: T,
wait: number
): (...args: Parameters<T>) => void {
let timeout: NodeJS.Timeout | null = null;
return function (...args: Parameters<T>) {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(() => {
func(...args);
}, wait);
};
}