Debounce – How to Delay a Function in JavaScript (JS ES6 Example)

PHOTO EMBED

Mon Jun 06 2022 10:52:14 GMT+0000 (Coordinated Universal Time)

Saved by @sabi_k #javascript

function debounce(func, timeout = 300){
  let timer;
  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => { func.apply(this, args); }, timeout);
  };
}
function saveInput(){
  console.log('Saving data');
}
const processChange = debounce(() => saveInput());
content_copyCOPY

https://www.freecodecamp.org/news/javascript-debounce-example/