@bit-ui-libs/common
Version:
This library was generated with [Nx](https://nx.dev).
9 lines • 380 B
text/typescript
// Source: https://decipher.dev/30-seconds-of-typescript/docs/debounce/
export const debounce = <TFunction extends (...args: any[]) => any>(fn: TFunction, ms = 300) => {
let timeoutId: ReturnType<typeof setTimeout>;
return function (this: any, ...args: any[]) {
clearTimeout(timeoutId);
// @ts-ignore
timeoutId = setTimeout(() => fn.apply(this, args), ms);
};
};