JSFiddle - React, Tailwind, and code Playground
by Aakash Khapare M
HTML
<div id="my-div">
</div>
<button id="me-btn">
My button
</button>
JavaScript
let b = document.getElementById('me-btn');
let d = document.getElementById('my-div');
let timer;
let debounce = (yourFunc) => {
return () => {
if(timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
yourFunc();
}, 1000);
}
}
b.addEventListener('click', function() {
console.log('you clicked!')
debounce(() => { console.log('Debouced function') })()
});