JSFiddle - React, Tailwind, and code Playground
by brigand
JavaScript
const debounce = (callback, ms) => {
let timer = null;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => {
callback.apply(this, args);
}, ms);
};
};
const saveDateAndRefresh = debounce(async function (param) {
console.log(param);
}, 750)
for (let i = 0; i < 10; i++) {
saveDateAndRefresh(i);
}