export function debounce(fn, wait = 250) {↵
let timer;↵
return function (...args) {↵
clearTimeout(timer);↵
timer = setTimeout(() => fn.apply(this, args), wait);↵
};↵
}↵
↵
const search = debounce((query) => {↵
fetch(`/api/search?q=${encodeURIComponent(query)}`)↵
.then((res) => res.json())↵
.then((results) => render(results));↵
}, 300);
Click here or press any key to type