Skip to content

Instantly share code, notes, and snippets.

@srikiranvelpuri
Last active May 6, 2024 11:24
Show Gist options
  • Save srikiranvelpuri/f3962dcda408ab5396d5a8a16f0c9923 to your computer and use it in GitHub Desktop.
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.
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