From a48b623822925b8ba4e71c495a56d8dfe81dd476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Fri, 24 Oct 2025 01:26:01 +0200 Subject: [PATCH] Fix --- packages/effect-fc/src/SubscriptionRef.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/effect-fc/src/SubscriptionRef.ts b/packages/effect-fc/src/SubscriptionRef.ts index 9891abd..eb7e9b8 100644 --- a/packages/effect-fc/src/SubscriptionRef.ts +++ b/packages/effect-fc/src/SubscriptionRef.ts @@ -31,16 +31,17 @@ export const useSubscriptionRefState: { export const useSubscriptionRefFromState: { (state: readonly [A, React.Dispatch>]): Effect.Effect, never, Scope.Scope> } = Effect.fnUntraced(function*([value, setValue]) { - const ref = yield* Component.useOnMount(() => SubscriptionRef.make(value)) - - yield* Component.useReactEffect(() => Effect.forkScoped( - Stream.runForEach( - Stream.changesWith(ref.changes, Equivalence.strict()), - v => Effect.sync(() => setValue(v)), - ) + const ref = yield* Component.useOnChange(() => Effect.tap( + SubscriptionRef.make(value), + ref => Effect.forkScoped( + Stream.runForEach( + Stream.changesWith(ref.changes, Equivalence.strict()), + v => Effect.sync(() => setValue(v)), + ) + ), ), [setValue]) - yield* Component.useReactEffect(() => Ref.set(ref, value), [value]) + yield* Component.useReactEffect(() => Ref.set(ref, value), [value]) return ref })