Files
ba6d927b-c689-429a-a56a-6e5…/src/utils/debounce.ts
Nikolay Pecheniev 008111d2ac Initial commit
2026-02-06 13:19:30 +02: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);
};
}