JSFiddle - React, Tailwind, and code Playground

by brigand

JavaScript

const saveDateAndRefresh = async () => {
    console.log('saveDateAndRefresh');
};

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

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


const f = debounce(saveDateAndRefresh, 750);
for (let i = 0; i < 10; i++) { f(); }