Created
January 6, 2022 09:59
-
-
Save lior-amsalem/806ee324de3ffe9337b85fb69c0c473a to your computer and use it in GitHub Desktop.
debounce function to reduce calls to a target location (api/data writing etc)
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
// debounce.js | |
export const debounce = (fnc, delay) => { | |
let time; | |
return function toBeExecuted(...args) { | |
const later = () => { | |
clearTimeout(time); | |
fnc(...args); | |
}; | |
clearTimeout(time); | |
time = setTimeout(later, delay); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment