Created
March 22, 2023 09:45
-
-
Save oidualc/38e710b3a94b16c94ce227cd8e275a70 to your computer and use it in GitHub Desktop.
debounce.ts
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
export function debounce<F extends (...args: Parameters<F>) => ReturnType<F>>( | |
func: F, | |
waitFor: number | |
): (...args: Parameters<F>) => void { | |
let timeout: ReturnType<typeof setTimeout>; | |
return (...args: Parameters<F>) => { | |
clearTimeout(timeout); | |
timeout = setTimeout(() => func(...args), waitFor); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment