-
-
Save electerious/2a49a51c62c9a71c8454 to your computer and use it in GitHub Desktop.
How to **correctly** debounce an event that will be triggered many times with identical arguments.
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
const debounce = function(fn, duration) { | |
let timeout = null | |
return (...args) => { | |
clearTimeout(timeout) | |
timeout = setTimeout(() => fn(...args), duration) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: