@@ -31,13 +31,14 @@ export const useFC: {
|
|||||||
self: ReactComponent<E, R, P>,
|
self: ReactComponent<E, R, P>,
|
||||||
options?: ReactHook.ScopeOptions,
|
options?: ReactHook.ScopeOptions,
|
||||||
) {
|
) {
|
||||||
const runtime = yield* Effect.runtime<Exclude<R, Scope.Scope>>()
|
const runtimeRef = React.useRef<Runtime.Runtime<Exclude<R, Scope.Scope>>>(null!)
|
||||||
|
runtimeRef.current = yield* Effect.runtime<Exclude<R, Scope.Scope>>()
|
||||||
|
|
||||||
return React.useMemo(() => function ScopeProvider(props: P) {
|
return React.useMemo(() => function ScopeProvider(props: P) {
|
||||||
const scope = Runtime.runSync(runtime)(ReactHook.useScope(options))
|
const scope = Runtime.runSync(runtimeRef.current)(ReactHook.useScope(options))
|
||||||
|
|
||||||
const FC = React.useMemo(() => {
|
const FC = React.useMemo(() => {
|
||||||
const f = (props: P) => Runtime.runSync(runtime)(
|
const f = (props: P) => Runtime.runSync(runtimeRef.current)(
|
||||||
Effect.provideService(self(props), Scope.Scope, scope)
|
Effect.provideService(self(props), Scope.Scope, scope)
|
||||||
)
|
)
|
||||||
f.displayName = self.displayName ?? "Anonymous"
|
f.displayName = self.displayName ?? "Anonymous"
|
||||||
@@ -46,7 +47,7 @@ export const useFC: {
|
|||||||
|
|
||||||
return React.createElement(FC, props)
|
return React.createElement(FC, props)
|
||||||
}, Array.from(
|
}, Array.from(
|
||||||
Context.omit(...nonReactiveTags)(runtime.context).unsafeMap.values()
|
Context.omit(...nonReactiveTags)(runtimeRef.current.context).unsafeMap.values()
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user