Skip to content

Instantly share code, notes, and snippets.

@dorianbayart
Created October 26, 2022 22:43
Show Gist options
  • Save dorianbayart/bf2bd559ab33b53360357838139dfc9a to your computer and use it in GitHub Desktop.
Save dorianbayart/bf2bd559ab33b53360357838139dfc9a to your computer and use it in GitHub Desktop.
Utils - Debounce function
// 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