Created
September 15, 2021 22:00
-
-
Save ajitid/79978b4d6225041b962e13d2f4dc12b9 to your computer and use it in GitHub Desktop.
Debounce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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