Skip to content

Instantly share code, notes, and snippets.

@lior-amsalem
Created January 6, 2022 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lior-amsalem/806ee324de3ffe9337b85fb69c0c473a to your computer and use it in GitHub Desktop.
Save lior-amsalem/806ee324de3ffe9337b85fb69c0c473a to your computer and use it in GitHub Desktop.
debounce function to reduce calls to a target location (api/data writing etc)
// debounce.js
export const debounce = (fnc, delay) => {
let time;
return function toBeExecuted(...args) {
const later = () => {
clearTimeout(time);
fnc(...args);
};
clearTimeout(time);
time = setTimeout(later, delay);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment