Created
November 22, 2019 00:21
-
-
Save JonathonAshworth/60237ef7e6a2f89cf45b3ae1deb76771 to your computer and use it in GitHub Desktop.
Function debounce
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
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