0.1.0 #1
@@ -85,6 +85,33 @@ export const useFC: {
|
||||
))
|
||||
})
|
||||
|
||||
export const useSuspenseFC: {
|
||||
<E, R, P extends {}>(
|
||||
self: Component<E, R, P>
|
||||
): Effect.Effect<React.FC<P>, never, Exclude<R, Scope.Scope>>
|
||||
} = Effect.fn("useSuspenseFC")(function* <E, R, P extends {}>(
|
||||
self: Component<E, R, P>
|
||||
) {
|
||||
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) {
|
||||
const scope = Runtime.runSync(runtimeRef.current)(Hook.useScope([], self.options))
|
||||
|
||||
const FC = React.useMemo(() => {
|
||||
const f = (props: P) => Runtime.runSync(runtimeRef.current)(
|
||||
Effect.provideService(self(props), Scope.Scope, scope)
|
||||
)
|
||||
f.displayName = self.displayName ?? "Anonymous"
|
||||
return f
|
||||
}, [scope])
|
||||
|
||||
return React.createElement(FC, props)
|
||||
}, Array.from(
|
||||
Context.omit(...nonReactiveTags)(runtimeRef.current.context).unsafeMap.values()
|
||||
))
|
||||
})
|
||||
|
||||
export const use: {
|
||||
<E, R, P extends {}>(
|
||||
self: Component<E, R, P>,
|
||||
|
||||
Reference in New Issue
Block a user