Last active
October 19, 2023 22:45
-
-
Save treyhuffine/2ced8b8c503e5246e2fd258ddbd21b8c to your computer and use it in GitHub Desktop.
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
// Originally inspired by David Walsh (https://davidwalsh.name/javascript-debounce-function) | |
// Returns a function, that, as long as it continues to be invoked, will not | |
// be triggered. The function will be called after it stops being called for | |
// `wait` milliseconds. | |
const debounce = (func, wait) => { | |
let timeout; | |
return function executedFunction(...args) { | |
const later = () => { | |
clearTimeout(timeout); | |
func(...args); | |
}; | |
clearTimeout(timeout); | |
timeout = setTimeout(later, wait); | |
}; | |
}; |
So simple yet so useful, thanks a lot
Thanks! Here's a full article as well - https://levelup.gitconnected.com/debounce-in-javascript-improve-your-applications-performance-5b01855e086?source=friends_link&sk=609d18e56befb764f6606141a2eaf481
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So simple yet so useful, thanks a lot