Last active
May 6, 2024 11:24
-
-
Save srikiranvelpuri/f3962dcda408ab5396d5a8a16f0c9923 to your computer and use it in GitHub Desktop.
A pure JavaScript debounce function for optimizing function calls, particularly useful for handling rapid user input events.
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
function debounce(func, delay) { | |
let timeoutId; | |
return function () { | |
const context = this; | |
const args = arguments; | |
clearTimeout(timeoutId); | |
timeoutId = setTimeout(() => { | |
func.apply(context, args); | |
}, delay); | |
}; | |
} | |
export default debounce; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment