@homeostate/store-valtio
v0.2.2
Published
Valtio adapter for @homeostate/core
Maintainers
Readme
@homeostate/store-valtio
Valtio store adapter for
@homeostate/core.
It keeps a Valtio proxy in sync with a CRDT backend such as Yjs, Loro or Automerge.
Install
npm install @homeostate/core @homeostate/store-valtio valtio @homeostate/crdt-yjs yjsvaltio 2 is a peer dependency.
Usage
import * as Y from "yjs";
import { proxy } from "valtio";
import { createSyncEngine } from "@homeostate/core";
import { createYjsBackend } from "@homeostate/crdt-yjs";
import { createValtioAdapter } from "@homeostate/store-valtio";
const state = proxy({
todos: [] as { id: string; title: string; done: boolean }[],
filter: "all",
});
const engine = createSyncEngine(
createYjsBackend(new Y.Doc(), "shared"),
createValtioAdapter(state),
);
engine.connect();
state.todos.push({ id: crypto.randomUUID(), title: "Write docs", done: false });Mutate the proxy as usual. Remote changes mutate only the paths that differ, so components
reading unchanged subtrees through useSnapshot do not re-render.
License
MIT — see LICENSE.
