Skip to content

Commit

Permalink
fix!: remove "lazy" option for useWatchEffect
Browse files Browse the repository at this point in the history
Setting lazy to true causes the effect to never be executed.
  • Loading branch information
hlysine committed May 23, 2023
1 parent 13359e4 commit 3eee2f7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,6 @@ export const effect = (
return runner;
};

type UseWatchEffectOptions = Pick<
ReactiveEffectOptions,
'lazy' | 'onTrack' | 'onTrigger'
>;

/**
* The hook version of `effect` from `@vue/reactivity`.
*
Expand Down Expand Up @@ -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<ReactiveEffectRunner | null>(null);
if (reactiveRef.current === null) {
reactiveRef.current = effect(fn, options);
reactiveRef.current = effect(fn, { ...options, lazy: false });
onScopeDispose(() => {
reactiveRef.current = null;
});
Expand Down

0 comments on commit 3eee2f7

Please sign in to comment.