@@ -1,11 +1,19 @@
|
||||
import { Container, Flex, Heading, Slider, Text, TextField } from "@radix-ui/themes"
|
||||
import { createFileRoute } from "@tanstack/react-router"
|
||||
import { Console, Effect } from "effect"
|
||||
import { Async, Component, Memoized } from "effect-fc-next"
|
||||
import * as React from "react"
|
||||
import { fetchPost } from "@/post"
|
||||
import { runtime } from "@/runtime"
|
||||
|
||||
|
||||
const fetchPost = (id: number) => Effect.sleep("500 millis").pipe(
|
||||
Effect.as({
|
||||
title: `Post ${id}`,
|
||||
body: `This is the content of post ${id}.`,
|
||||
}),
|
||||
)
|
||||
|
||||
|
||||
interface AsyncFetchPostViewProps {
|
||||
readonly id: number
|
||||
}
|
||||
@@ -13,6 +21,11 @@ interface AsyncFetchPostViewProps {
|
||||
const AsyncFetchPostView = Component.make("AsyncFetchPostView")(function*(
|
||||
props: AsyncFetchPostViewProps,
|
||||
) {
|
||||
yield* Component.useOnMount(() => Effect.gen(function*() {
|
||||
yield* Effect.addFinalizer(() => Console.log("AsyncFetchPostView unmounted"))
|
||||
yield* Console.log("AsyncFetchPostView mounted")
|
||||
}))
|
||||
|
||||
const post = yield* Component.useOnChange(
|
||||
() => fetchPost(props.id),
|
||||
[props.id],
|
||||
@@ -51,7 +64,7 @@ const AsyncRouteComponent = Component.make("AsyncRouteView")(function*() {
|
||||
onValueChange={([value]) => setId(value ?? 1)}
|
||||
/>
|
||||
|
||||
<AsyncFetchPost id={id} fallback={<Text>Loading post...</Text>} />
|
||||
<AsyncFetchPost id={id} />
|
||||
</Flex>
|
||||
</Container>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user