Skip to content

Instantly share code, notes, and snippets.

@giventofly
Created March 17, 2022 21:07
Show Gist options
  • Save giventofly/182137bd1d99fee9549b0ff15ef4e69c to your computer and use it in GitHub Desktop.
Save giventofly/182137bd1d99fee9549b0ff15ef4e69c to your computer and use it in GitHub Desktop.
debounce javascript
//search decks
document.getElementById("decktosearch").addEventListener("keyup", debounceSearchDeck);
const debounce = (callback, wait) => {
let timeoutId = null;
return (...args) => {
window.clearTimeout(timeoutId);
timeoutId = window.setTimeout(() => {
callback.apply(null, args);
}, wait);
};
}
const debounceSearchDeck = debounce((e) =>{
searchDeck(e.target.value);
}, 500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment