import { runtime } from "@/runtime" import { Flex, Text, TextField } from "@radix-ui/themes" import { createFileRoute } from "@tanstack/react-router" import { GetRandomValues, makeUuid4 } from "@typed/id" import { Effect } from "effect" import { Component, Memo, Suspense } from "effect-fc" import { Hooks } from "effect-fc/hooks" import * as React from "react" // Generator version const RouteComponent = Component.makeUntraced(function* AsyncRendering() { const MemoizedAsyncComponentFC = yield* MemoizedAsyncComponent const AsyncComponentFC = yield* AsyncComponent const [input, setInput] = React.useState("") return ( setInput(e.target.value)} />

Loading memoized...

, [])} />
) }).pipe( Component.withRuntime(runtime.context) ) // Pipeline version // const RouteComponent = Component.make("RouteComponent")(() => Effect.Do, // Effect.bind("VMemoizedAsyncComponent", () => Component.useFC(MemoizedAsyncComponent)), // Effect.bind("VAsyncComponent", () => Component.useFC(AsyncComponent)), // Effect.let("input", () => React.useState("")), // Effect.map(({ input: [input, setInput], VAsyncComponent, VMemoizedAsyncComponent }) => // // setInput(e.target.value)} // /> // // // // ), // ).pipe( // Component.withRuntime(runtime.context) // ) class AsyncComponent extends Component.makeUntraced(function* AsyncComponent() { const SubComponentFC = yield* SubComponent yield* Effect.sleep("500 millis") // Async operation // Cannot use React hooks after the async operation return ( Rendered! ) }).pipe( Suspense.suspense, Suspense.withOptions({ defaultFallback:

Loading...

}), ) {} class MemoizedAsyncComponent extends Memo.memo(AsyncComponent) {} class SubComponent extends Component.makeUntraced(function* SubComponent() { const [state] = React.useState(yield* Hooks.useOnce(() => Effect.provide(makeUuid4, GetRandomValues.CryptoRandom))) return {state} }) {} export const Route = createFileRoute("/dev/async-rendering")({ component: RouteComponent })