debounce

PHOTO EMBED

Wed Sep 15 2021 07:25:27 GMT+0000 (UTC)

Saved by @cxgarcia #typescript

export function debounce(fn, timeout = 1000) {
  let timeoutRef = null;

  return (...args) => {
    if (timeoutRef) clearTimeout(timeoutRef);

    timeoutRef = setTimeout(() => {
      return fn(...args);
    }, timeout);
  };
}
content_copyCOPY