Quick actions

cmd+k|ctrl+k

Navigation

Languages

!Debounce

Snippet info

Language

JavaScript

Visibility

public

Author

paulkotov

Created

2023-10-01T08:59:15.468173Z

Updated

2023-10-01T09:05:41.399767Z

export const debounce = (func, ms) => {
  let timeoutId;
  const context = this;
  const result = (...args) => {
    clearTimeout(timeoutId);
    timeoutId = setTimeout(() => func.apply(context, args), ms);
  };
  result.cancel = () => clearTimeout(timeoutId);

  return result;
};
INFO