export function debounce(fn, wait = 300) { let timer; return (...args) => { clearTimeout(timer); timer = setTimeout(() => fn(...args), wait); }; } // usage: const onSearch = debounce((q) => console.log(q), 400);