Debounce a search handler

Delay a search or input handler until the user pauses typing.

Original Pearto instructional example. Test it in your own environment and adapt it to your requirements.

News & updates

No news stories have been linked to this profile.

Search news coverage ↗

Sources & useful links

No publisher or independent source links have been added to this entry.

Suggest a source or correction ↗
function debounce(fn, ms=250) {
  let timer;
  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => fn(...args), ms);
  };
}
const search = debounce(console.log);
search('tools');