Created
October 8, 2023 07:47
-
-
Save renews/8bd0e66a5fb908c31c3be47d8f79d867 to your computer and use it in GitHub Desktop.
Debouce Function
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(fn, delay) { | |
let timeoutId; | |
return (...args) => { | |
clearTimeout(timeoutId); | |
timeoutId = setTimeout(() => fn(...args), delay); | |
}; | |
} | |
to call it | |
const debouncedFunction = debounce(functionToDebounce, 1000); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment