Skip to content

Instantly share code, notes, and snippets.

@mainendra
Created December 13, 2022 17:33
Show Gist options
  • Save mainendra/18eff704a4a2ba1aaf536bfda72227d2 to your computer and use it in GitHub Desktop.
Save mainendra/18eff704a4a2ba1aaf536bfda72227d2 to your computer and use it in GitHub Desktop.
function debounce<T extends [...T], U>(callback: (...args: [...T]) => U, delayMs: number): (...args: [...T]) => void {
let timerId: any = null;
return (...args: [...T]) => {
clearTimeout(timerId);
timerId = setTimeout(() => callback(...args), delayMs);
};
}
export {
debounce
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment