This commit is contained in:
@@ -370,7 +370,7 @@ that behavior, pass their tags with `Component.withOptions({ nonReactiveTags:
|
||||
|
||||
## Provide Services To A Subtree
|
||||
|
||||
Use `Component.useContextFromLayer` when an Effect View component should provide
|
||||
Use `Component.useLayer` when an Effect View component should provide
|
||||
extra services to another Effect View component. It turns a `Layer` into a runtime
|
||||
context that can be provided to `.use`.
|
||||
|
||||
@@ -381,19 +381,19 @@ import { GreetingView } from "./Greeting"
|
||||
import { GreetingLive } from "./services"
|
||||
|
||||
export const GreetingPageView = Component.make("GreetingPage")(function* () {
|
||||
const context = yield* Component.useContextFromLayer(GreetingLive)
|
||||
const context = yield* Component.useLayer(GreetingLive)
|
||||
const Greeting = yield* GreetingView.use.pipe(Effect.provide(context))
|
||||
|
||||
return <Greeting name="Effect" />
|
||||
})
|
||||
```
|
||||
|
||||
The layer passed to `useContextFromLayer` should be stable. If a new layer value
|
||||
The layer passed to `useLayer` should be stable. If a new layer value
|
||||
is created on every render, Effect View has to build a new context, which can
|
||||
cause unnecessary re-renders and scoped lifecycle restarts. Define static layers
|
||||
outside the component, or memoize layers that depend on React props or state.
|
||||
|
||||
Layers built with `useContextFromLayer` are scoped to the component that builds
|
||||
Layers built with `useLayer` are scoped to the component that builds
|
||||
them. That means service construction can register scoped logic, acquire
|
||||
resources, fork scoped fibers, and add finalizers that are tied to that
|
||||
component's lifecycle.
|
||||
|
||||
Reference in New Issue
Block a user