8 lines
242 B
TypeScript
8 lines
242 B
TypeScript
export const debounce = (fn: Function, ms = 300) => {
|
|
let timeoutId: ReturnType<typeof setTimeout>
|
|
return function (this: any, ...args: any[]) {
|
|
clearTimeout(timeoutId)
|
|
timeoutId = setTimeout(() => fn.apply(this, args), ms)
|
|
}
|
|
}
|