This commit is contained in:
@@ -19,6 +19,7 @@ function Root() {
|
||||
<Link to="/time">Time</Link>
|
||||
<Link to="/count">Count</Link>
|
||||
<Link to="/tests">Tests</Link>
|
||||
<Link to="/promise">Promise</Link>
|
||||
<Link to="/blank">Blank</Link>
|
||||
</Flex>
|
||||
</Container>
|
||||
|
||||
31
packages/example/src/routes/promise.tsx
Normal file
31
packages/example/src/routes/promise.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { R } from "@/reffuse"
|
||||
import { HttpClient } from "@effect/platform"
|
||||
import { createFileRoute } from "@tanstack/react-router"
|
||||
import { Console, Effect } from "effect"
|
||||
import { use, useMemo } from "react"
|
||||
|
||||
|
||||
export const Route = createFileRoute("/promise")({
|
||||
component: RouteComponent
|
||||
})
|
||||
|
||||
function RouteComponent() {
|
||||
|
||||
const runPromise = R.useRunPromise()
|
||||
|
||||
const promise = useMemo(() => HttpClient.HttpClient.pipe(
|
||||
Effect.flatMap(client => client.get("https://www.uuidtools.com/api/generate/v4")),
|
||||
HttpClient.withTracerPropagation(false),
|
||||
Effect.flatMap(res => res.json),
|
||||
Effect.tap(Console.log),
|
||||
|
||||
Effect.scoped,
|
||||
runPromise,
|
||||
), [runPromise])
|
||||
|
||||
const value = use(promise)
|
||||
|
||||
|
||||
return <div>Hello "/tests"!</div>
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { R } from "@/reffuse"
|
||||
import { createFileRoute } from "@tanstack/react-router"
|
||||
import { GetRandomValues, makeUuid4 } from "@typed/id"
|
||||
import { Console, Effect } from "effect"
|
||||
import { useEffect, useState } from "react"
|
||||
import { useMemo, useState } from "react"
|
||||
|
||||
|
||||
export const Route = createFileRoute("/tests")({
|
||||
@@ -22,20 +22,16 @@ function RouteComponent() {
|
||||
// ))
|
||||
|
||||
const runPromise = R.useRunPromise()
|
||||
const [promise, setPromise] = useState<Promise<void> | null>(null)
|
||||
const [, setValue] = useState("")
|
||||
|
||||
useEffect(() => {
|
||||
makeUuid4.pipe(
|
||||
Effect.provide(GetRandomValues.CryptoRandom),
|
||||
Effect.tap(id => Effect.sync(() => setValue(id))),
|
||||
Effect.andThen(Console.log),
|
||||
Effect.delay("1 second"),
|
||||
const promise = useMemo(() => makeUuid4.pipe(
|
||||
Effect.provide(GetRandomValues.CryptoRandom),
|
||||
Effect.tap(id => Effect.sync(() => setValue(id))),
|
||||
Effect.andThen(Console.log),
|
||||
Effect.delay("1 second"),
|
||||
|
||||
runPromise,
|
||||
setPromise,
|
||||
)
|
||||
}, [runPromise])
|
||||
runPromise,
|
||||
), [runPromise])
|
||||
|
||||
console.log(promise)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user