From 8bdb0a760d2d8a17ceddc537446b4bd10cfbf9c6 Mon Sep 17 00:00:00 2001 From: liuyib <1656081615@qq.com> Date: Tue, 26 Sep 2023 20:18:01 +0800 Subject: [PATCH] refactor: update --- packages/hooks/src/useDebounceFn/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/hooks/src/useDebounceFn/index.ts b/packages/hooks/src/useDebounceFn/index.ts index 24910f4b37..412f4da049 100644 --- a/packages/hooks/src/useDebounceFn/index.ts +++ b/packages/hooks/src/useDebounceFn/index.ts @@ -8,7 +8,7 @@ import isDev from '../utils/isDev'; type noop = (...args: any[]) => any; -function useDebounceFn(fn: T, options?: DebounceOptions) { +function useDebounceFn(fn: T, options: DebounceOptions = {}) { if (isDev) { if (!isFunction(fn)) { console.error(`useDebounceFn expected parameter is a function, got ${typeof fn}`); @@ -17,7 +17,8 @@ function useDebounceFn(fn: T, options?: DebounceOptions) { const fnRef = useLatest(fn); - const wait = options?.wait ?? 1000; + // https://github.com/alibaba/hooks/issues/2331 + const wait = 'wait' in options ? options.wait : 1000; const debounced = useMemo( () =>