JSFiddle - React, Tailwind, and code Playground
by Artem
JavaScript
'use strict';
const debounce = (fn, ms) => {
let timer;
return (...args) => {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
fn(...args);
}, ms);
};
};
const callback = () => console.log('click');
document.addEventListener('click', debounce(callback), 500);