Time fork test
Some checks failed
Lint / lint (push) Failing after 9s

This commit is contained in:
Julien Valverdé
2025-01-11 17:51:36 +01:00
parent e1a85fbb7e
commit 8ae59bdd93
5 changed files with 65 additions and 52 deletions

View File

@@ -0,0 +1,42 @@
import { Reffuse } from "@/reffuse"
import { createFileRoute } from "@tanstack/react-router"
import { Console, DateTime, Effect, Ref, Schedule, SubscriptionRef } from "effect"
import { useMemo } from "react"
export const Route = createFileRoute("/time")({
component: Time
})
function Time() {
const runtime = Reffuse.useRuntime()
const timeRef = useMemo(() => DateTime.now.pipe(
Effect.flatMap(SubscriptionRef.make),
runtime.runSync,
// eslint-disable-next-line react-hooks/exhaustive-deps
), [])
Reffuse.useFork(Effect.addFinalizer(() => Console.log("Component unmounted.")).pipe(
Effect.flatMap(() => DateTime.now),
Effect.flatMap(v => Ref.set(timeRef, v)),
Effect.repeat(Schedule.spaced("1 second")),
))
const [time] = Reffuse.useRefState(timeRef)
return (
<div className="container mx-auto">
<p className="text-center">
{DateTime.format(time, {
hour: "numeric",
minute: "numeric",
second: "numeric",
})}
</p>
</div>
)
}