import React from "react"; import { useY } from "react-yjs"; import * as Y from "yjs"; export const Todos: React.FC = () => { const [yTodos] = React.useState(() => { // initialize a Y.Doc and get the todos array // when the component mounts const yDoc = new Y.Doc(); return yDoc.getArray>("todos"); }); const todos = useY(yTodos); const [newTodo, setNewTodo] = React.useState(""); return ( <>
{ event.preventDefault(); const todo = new Y.Map(); todo.set("checked", false); todo.set("text", newTodo); yTodos.push([todo]); setNewTodo(""); }} >
    {todos.map((todo, index) => { return (
  • ); })}
Result: {JSON.stringify(todos, null, 2)}
); };