UNPKG

@bit-ui-libs/common

Version:
9 lines 380 B
// 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); }; };