JSFiddle - React, Tailwind, and code Playground

by Csaba Hellinger

HTML

<button id="btn">He</button>

JavaScript

const throttle = (func, time) => {
  let timer = null;
  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => func(...args), time);
  };
};


const func = name => console.log('hello', name);

const throttled = throttle(func, 1000);


document.querySelector('#btn').onclick = () => throttled('joe');
//window.addEventListener('resize', () => throttled('joe'));