From 3eee2f7fd2f9416297fd41804cd737b1725a3970 Mon Sep 17 00:00:00 2001 From: Henry Lin Date: Tue, 23 May 2023 21:11:38 +0800 Subject: [PATCH] fix!: remove "lazy" option for `useWatchEffect` Setting lazy to true causes the effect to never be executed. --- src/core.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/core.ts b/src/core.ts index eb6091b..5e16ddc 100644 --- a/src/core.ts +++ b/src/core.ts @@ -252,11 +252,6 @@ export const effect = ( return runner; }; -type UseWatchEffectOptions = Pick< - ReactiveEffectOptions, - 'lazy' | 'onTrack' | 'onTrigger' ->; - /** * The hook version of `effect` from `@vue/reactivity`. * @@ -289,11 +284,17 @@ type UseWatchEffectOptions = Pick< */ export const useWatchEffect = ( fn: () => CleanupFn | void, - options?: UseWatchEffectOptions + options?: DebuggerOptions ): void => { + if (options && 'lazy' in options && options.lazy) { + console.warn( + '"lazy" option is not supported for useWatchEffect because the effect has to be run to collect dependencies. ' + + 'Use watchEffect if you want to control the execution timing of the effect.' + ); + } const reactiveRef = useRef(null); if (reactiveRef.current === null) { - reactiveRef.current = effect(fn, options); + reactiveRef.current = effect(fn, { ...options, lazy: false }); onScopeDispose(() => { reactiveRef.current = null; });