Skip to content

Instantly share code, notes, and snippets.

@ajitid
Created September 15, 2021 22:00
Show Gist options
  • Save ajitid/79978b4d6225041b962e13d2f4dc12b9 to your computer and use it in GitHub Desktop.
Save ajitid/79978b4d6225041b962e13d2f4dc12b9 to your computer and use it in GitHub Desktop.
Debounce
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function debounce<F extends (...arguments_: any) => any>(
function_: F,
wait = 200
): F {
let timeoutID: number;
return function (this: unknown, ...arguments_: Parameters<F>) {
clearTimeout(timeoutID);
timeoutID = window.setTimeout(() => {
function_.apply(this, arguments_);
}, wait);
} as F;
}
export default debounce;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment