Local-first state management for TypeScript. You describe your state with a schema, and a store keeps it in conflict-free replicated data types (CRDTs), so changes made offline, in other tabs, or on other devices merge into the same result. Sync engines connect the store to IndexedDB, other tabs, or a server.
npm install @nn/react @nn/schema @nn/indexdb-sync @nn/sse-syncimport { IndexDbSync } from "@nn/indexdb-sync";
import { createStore } from "@nn/react";
import { array, object, string } from "@nn/schema";
import { SseSync } from "@nn/sse-sync";
export const { store, useRead, useUpdate } = createStore(
object({ todos: array(object({ id: string(), title: string() })) }),
);
const persistence = new IndexDbSync(store);
const remote = new SseSync(store, new URL("https://example.com/sync"));
remote.onError((error) => console.error(error));
persistence.connect();
remote.connect();IndexDbSync saves the state on the device and SseSync syncs it with a server. Use either one or both. Engines start idle, so you can add listeners before calling connect().
apps/example-reactis a kanban board that works offline, syncs between tabs, and merges edits from other devices through a server.apps/example-serveris the sync server the board and the Node examples connect to.apps/example-nodewatches this repository forTODOcomments and adds them to the board as tickets over server-sent events.apps/example-schemaholds the schema both apps share.