Created
March 3, 2023 11:21
-
-
Save joekolade/8873eb75012dc6bc9cd0e315ea30e230 to your computer and use it in GitHub Desktop.
[JS Debounce] Simple debouncer function
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
| /* | |
| @param : fn => the function to convert | |
| @param : time => the time delay for debounce | |
| */ | |
| function debounce(fn, delay) { | |
| let timer = null | |
| return (...args) => { | |
| if (timer) clearTimeout(timer) | |
| timer = setTimeout(() => fn(...args), delay) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment