Created
October 26, 2022 22:43
-
-
Save dorianbayart/bf2bd559ab33b53360357838139dfc9a to your computer and use it in GitHub Desktop.
Utils - Debounce function
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
// Utils - Debounce function | |
let debounceTimer | |
function debounce(func, timeout = 500) { | |
return (...args) => { | |
clearTimeout(debounceTimer) | |
debounceTimer = setTimeout(() => { func.apply(this, args) }, timeout) | |
} | |
} | |
// Use it | |
function myFunction(args) {} | |
debounce(myFunction)(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment