forked from M3-Academy/m3-academy-template-vtexio
15 lines
379 B
TypeScript
15 lines
379 B
TypeScript
export const debounce = <T extends (...args: any[]) => any>(
|
|
callback: T,
|
|
waitFor: number
|
|
): any => {
|
|
let timeout: any = 0;
|
|
return (...args: Parameters<T>): ReturnType<T> => {
|
|
let result: any;
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(() => {
|
|
result = callback(...args);
|
|
}, waitFor);
|
|
return result;
|
|
};
|
|
};
|