Tests
All checks were successful
Lint / lint (push) Successful in 14s

This commit is contained in:
Julien Valverdé
2025-06-25 13:38:44 +02:00
parent 1769c4074d
commit 8007c2693a
2 changed files with 21 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
import { Box, Text, TextField } from "@radix-ui/themes"
import { createFileRoute } from "@tanstack/react-router"
import { Console, Effect, Layer, ManagedRuntime, Runtime } from "effect"
import { ReactComponent } from "effect-components"
import * as React from "react"
@@ -11,25 +12,15 @@ export const Route = createFileRoute("/effect-component-tests")({
function RouteComponent() {
const runtime = React.useMemo(() => ManagedRuntime.make(Layer.empty), [])
return runtime.runSync(Effect.gen(function* RouteComponent() {
const MyTest = yield* useFunctionComponent(MyTestComponent)
return <>
<MyTest />
</>
}))
return <>
{runtime.runSync(MyTestComponent.use(Component => (
<Component />
)))}
</>
}
const useFunctionComponent = <P, E, R>(
self: (props: P) => Effect.Effect<React.ReactNode, E, R>
): Effect.Effect<React.FC<P>, never, R> => Effect.gen(function* useFunctionComponent() {
const runtime = yield* Effect.runtime<R>()
return React.useCallback((props: P) => Runtime.runSync(runtime)(self(props)), [runtime])
})
const MyTestComponent = Effect.fn(function*(props?: { readonly value?: string }) {
const MyTestComponent = ReactComponent.make(Effect.fn(function* MyTestComponent(props?: { readonly value?: string }) {
const [state, setState] = React.useState("value")
const effectValue = yield* Effect.succeed(`state: ${ state }`)
@@ -45,7 +36,7 @@ const MyTestComponent = Effect.fn(function*(props?: { readonly value?: string })
/>
</Box>
</>
})
}))
const useEffect = <A, E, R>(