Debounce (sketch)
Delay execution until the user pauses.
function debounce(fn, ms = 300) {
let t;
return (...args) => {
clearTimeout(t);
t = setTimeout(() => fn(...args), ms);
};
}
const onSearch = debounce((q) => console.log('buscar', q));
input.addEventListener('input', (e) => onSearch(e.target.value));
Copie o snippet e adapte. Pratique nos exemplos de JavaScript.