A state synchronization library for React frontends that uses a WebSocket and JSON/JSON Patch protocol to keep Zustand stores in sync with a backend (Python reference implementation available). Current stable version is 0.8.3. Release cadence is irregular; actively maintained as of 2025. Key differentiators: follows Zustand's philosophy of state outside React, uses Immer for efficient JSON Patch generation, minimal boilerplate with a synced() middleware, and provides a lightweight Session object for WebSocket management. Requires React 18+, React DOM 18+, and Zustand 5.x. Peer dependencies include zustand@^5.0.0.
npm install ws-syncNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a WebSocket session and a Zustand store synced with the backend, then uses it in a React component.
Install zustand@^5.0.0: npm install zustand@5
Upgrade React to v18+
Ensure set() is called inside the same function before sync(). Example: set({ currentNoteId: id }); sync();Assign a unique key to each synced store (e.g., 'Notes', 'Todos').
Call session.connect() explicitly: const session = new Session(...); session.connect();
Run: npm install ws-sync zustand (and ensure peer deps are met)
Ensure session.connect() is called after new Session(...), and wait for the connection promise if using async/await.
Use named import: import { synced } from 'ws-sync'Ensure hooks are called at the top level of a React component, not inside loops, conditions, or nested functions.