Created
May 4, 2024 02:56
-
-
Save amitasaurus/e4c275199d2f1d4be2b5a56a8c4a223e to your computer and use it in GitHub Desktop.
implementation of debounce in TypeScript
This file contains hidden or 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
function debounce( | |
func: (...args: any[]) => any, | |
delay: number | |
): (...args: any[]) => void { | |
let timeoutId: ReturnType<typeof setTimeout> | null; | |
return function debouncedFunction(...args: any[]): void { | |
clearTimeout(timeoutId!); | |
timeoutId = setTimeout(() => { | |
func(...args); | |
}, delay); | |
}; | |
} | |
export default debounce; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment