Files
a9f2c3f1-a7c2-46d1-9e79-8ba…/src/utils/debounce.ts
2026-03-06 04:31:55 +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);
};
}