diff --git a/packages/effect-fc/src/Component.ts b/packages/effect-fc/src/Component.ts index 69a24f4..6ca3adc 100644 --- a/packages/effect-fc/src/Component.ts +++ b/packages/effect-fc/src/Component.ts @@ -613,25 +613,15 @@ export const useCallbackPromise: { }) export namespace useContext { - export type Options = useScope.Options + export type Options = useOnChange.Options } -export const useContext: { - ( - layer: Layer.Layer, - options?: useContext.Options, - ): Effect.Effect, E, RIn> -} = Effect.fnUntraced(function* ( +export const useContext = ( layer: Layer.Layer, options?: useContext.Options, -) { - const scope = yield* useScope([layer], options) - - return yield* useOnChange(() => Effect.context().pipe( - Effect.map(context => ManagedRuntime.make(Layer.provide(layer, Layer.succeedContext(context)))), - Effect.tap(runtime => Effect.addFinalizer(() => runtime.disposeEffect)), - Effect.andThen(runtime => runtime.runtimeEffect), - Effect.andThen(runtime => runtime.context), - Effect.provideService(Scope.Scope, scope), - ), [scope]) -}) +): Effect.Effect, E, RIn> => useOnChange(() => Effect.context().pipe( + Effect.map(context => ManagedRuntime.make(Layer.provide(layer, Layer.succeedContext(context)))), + Effect.tap(runtime => Effect.addFinalizer(() => runtime.disposeEffect)), + Effect.andThen(runtime => runtime.runtimeEffect), + Effect.andThen(runtime => runtime.context), +), [layer], options)