JSFiddle - React, Tailwind, and code Playground

by brigand

JavaScript

const debounce = (callback, ms) => {
    let timer;

    return function () {
        clearTimeout(timer);
        timer = setTimeout(function () {
            callback.call(this);
        }.bind(this), ms);
    };
};

const saveDateAndRefresh = debounce(async function () {
	console.log('saveDateAndRefresh');
}, 750)


for (let i = 0; i < 10; i++) {
	saveDateAndRefresh();
}