Files
2cfe6d53-e0b4-4e73-93f7-348…/src/utils/debounce.ts
2026-02-21 16:47:28 +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);
};
}