From f2e6e5ae08f510017e4df6b814f2f21667f7a5f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sun, 6 Jul 2025 21:57:16 +0200 Subject: [PATCH] Fix --- packages/example/src/todo/Todo.tsx | 41 +++++++++++++----------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/packages/example/src/todo/Todo.tsx b/packages/example/src/todo/Todo.tsx index 573bef2..bb34ac4 100644 --- a/packages/example/src/todo/Todo.tsx +++ b/packages/example/src/todo/Todo.tsx @@ -4,7 +4,6 @@ import { GetRandomValues, makeUuid4 } from "@typed/id" import { Chunk, Effect, Match, Option, Ref, Runtime, SubscriptionRef } from "effect" import { Component, Hook } from "effect-fc" import { SubscriptionSubRef } from "effect-fc/types" -import * as React from "react" import { FaArrowDown, FaArrowUp } from "react-icons/fa" import { FaDeleteLeft } from "react-icons/fa6" import { TodosState } from "./TodosState.service" @@ -21,35 +20,33 @@ const makeTodo = makeUuid4.pipe( export type TodoProps = ( - | { - readonly _tag: "new" - readonly index?: never - } - | { - readonly _tag: "edit" - readonly index: number - } + | { readonly _tag: "new", readonly index?: never } + | { readonly _tag: "edit", readonly index: number } ) export const Todo = Component.make(function* Todo(props: TodoProps) { const runtime = yield* Effect.runtime() const state = yield* TodosState - const ref = yield* Hook.useMemo(() => Match.value(props).pipe( + const [ref, contentRef] = yield* Hook.useMemo(() => Match.value(props).pipe( Match.tag("new", () => Effect.andThen(makeTodo, SubscriptionRef.make)), Match.tag("edit", ({ index }) => Effect.succeed(SubscriptionSubRef.makeFromChunkRef(state.ref, index))), Match.exhaustive, + + Effect.map(ref => [ + ref, + SubscriptionSubRef.makeFromPath(ref, ["content"]), + ] as const), ), [props._tag, props.index]) - const contentRef = React.useMemo(() => SubscriptionSubRef.makeFromPath(ref, ["content"]), [ref]) - const [todo, todosSize] = yield* Hook.useSubscribeRefs(ref, state.sizeRef) + const [content, size] = yield* Hook.useSubscribeRefs(contentRef, state.sizeRef) return (