Fix
All checks were successful
Lint / lint (push) Successful in 15s

This commit is contained in:
Julien Valverdé
2025-07-01 16:31:30 +02:00
parent 02ee2c10cc
commit 8025ec4a22
2 changed files with 12 additions and 9 deletions

View File

@@ -24,15 +24,17 @@ export const withDisplayName: {
export const useFC: { export const useFC: {
<E, R, P extends {} = {}>( <E, R, P extends {} = {}>(
self: ReactComponent<E, R, P> self: ReactComponent<E, R, P>,
options?: ReactHook.ScopeOptions,
): Effect.Effect<React.FC<P>, never, Exclude<R, Scope.Scope>> ): Effect.Effect<React.FC<P>, never, Exclude<R, Scope.Scope>>
} = Effect.fnUntraced(function* <E, R, P extends {}>( } = Effect.fnUntraced(function* <E, R, P extends {}>(
self: ReactComponent<E, R, P> self: ReactComponent<E, R, P>,
options?: ReactHook.ScopeOptions,
) { ) {
const runtime = yield* Effect.runtime<Exclude<R, Scope.Scope>>() const runtime = 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()) const scope = Runtime.runSync(runtime)(ReactHook.useScope(options))
const FC = React.useMemo(() => { const FC = React.useMemo(() => {
const f = (props: P) => Runtime.runSync(runtime)( const f = (props: P) => Runtime.runSync(runtime)(
@@ -52,9 +54,10 @@ export const use: {
<E, R, P extends {} = {}>( <E, R, P extends {} = {}>(
self: ReactComponent<E, R, P>, self: ReactComponent<E, R, P>,
fn: (Component: React.FC<P>) => React.ReactNode, fn: (Component: React.FC<P>) => React.ReactNode,
options?: ReactHook.ScopeOptions,
): Effect.Effect<React.ReactNode, never, Exclude<R, Scope.Scope>> ): Effect.Effect<React.ReactNode, never, Exclude<R, Scope.Scope>>
} = Effect.fnUntraced(function*(self, fn) { } = Effect.fnUntraced(function*(self, fn, options) {
return fn(yield* useFC(self)) return fn(yield* useFC(self, options))
}) })
export const withRuntime: { export const withRuntime: {

View File

@@ -68,10 +68,10 @@ const MyTestComponent = pipe(
const service = yield* SubService const service = yield* SubService
const [value] = yield* ReactHook.useSubscribeRefs(service.ref) const [value] = yield* ReactHook.useSubscribeRefs(service.ref)
yield* ReactHook.useMemo(() => Effect.andThen( // yield* ReactHook.useMemo(() => Effect.andThen(
Effect.addFinalizer(() => Console.log("MyTestComponent umounted")), // Effect.addFinalizer(() => Console.log("MyTestComponent umounted")),
Console.log("MyTestComponent mounted"), // Console.log("MyTestComponent mounted"),
), []) // ), [])
return <> return <>
<Box> <Box>