Skip to content

Commit

Permalink
feat(project): add debounce function
Browse files Browse the repository at this point in the history
  • Loading branch information
royschut committed May 6, 2021
1 parent 47b409d commit b54753f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/utils/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function debounce<T extends (...args: any[]) => void>(callback: T, wait = 200) {
let timeout: NodeJS.Timeout | null;
const callable = (...args: unknown[]) => {
if (timeout) clearTimeout(timeout);
timeout = setTimeout(() => callback(...args), wait);
};
return callable;
}

0 comments on commit b54753f

Please sign in to comment.