Debounce in Js

PHOTO EMBED

Wed Sep 04 2024 07:06:48 GMT+0000 (Coordinated Universal Time)

Saved by @danishyt96 #javascript

const input = document.getElementById('input');


const debounc = (func, waitTime) => {
    let timer;
    return (...args) => {
        clearTimeout(timer);
        timer = setTimeout(() => {
            func(...args);
        }, waitTime);
    };
}

function getData(e) {
    console.log(e.target.value)
};

const debouncApi = debounc(getData, 1000);


input.addEventListener('input', debouncApi);
content_copyCOPY