Skip to content

Instantly share code, notes, and snippets.

@aydgn
Created September 24, 2022 16:55
Show Gist options
  • Select an option

  • Save aydgn/ebc513b2fcd3b64d626153ab4a59e8ce to your computer and use it in GitHub Desktop.

Select an option

Save aydgn/ebc513b2fcd3b64d626153ab4a59e8ce to your computer and use it in GitHub Desktop.
Debounce JS
const debounce = (callback, wait = 1000) => {
let timeoutId = null;
return (...args) => {
window.clearTimeout(timeoutId);
timeoutId = window.setTimeout(() => {
callback(...args);
}, wait);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment