debounce.js

By Guest User · 2 months ago · Javascript · 227 B
raw download duplicate
export function debounce(fn, wait = 250) {
  let timer = null;

  return function debounced(...args) {
    clearTimeout(timer);
    timer = setTimeout(() => {
      timer = null;
      fn.apply(this, args);
    }, wait);
  };
}