Skip to content

Instantly share code, notes, and snippets.

@JonathonAshworth
Created November 22, 2019 00:21
Show Gist options
  • Save JonathonAshworth/60237ef7e6a2f89cf45b3ae1deb76771 to your computer and use it in GitHub Desktop.
Save JonathonAshworth/60237ef7e6a2f89cf45b3ae1deb76771 to your computer and use it in GitHub Desktop.
Function debounce
export const debounce = (f, delay) => {
let timer = null
return (...args) => {
const execute = () => {
timer = null
f(...args)
}
if (timer !== null)
window.clearTimeout(timer)
timer = window.setTimeout(execute, delay)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment