Files
84b96af2-a04b-4db5-9492-2de…/src/utils/debounce.ts
2026-03-03 08:20:46 +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);
};
}