Zustand adapter for state-sync — automatic store synchronization
npm install @statesync/zustandZustand adapter for state-sync. Applies snapshots to a Zustand store.
``bash`
npm install @statesync/zustand @statesync/core
`typescript
import { createRevisionSync } from '@statesync/core';
import { createZustandSnapshotApplier } from '@statesync/zustand';
import { create } from 'zustand';
const useSettingsStore = create(() => ({
theme: 'light',
lang: 'en',
}));
const applier = createZustandSnapshotApplier(useSettingsStore);
const handle = createRevisionSync({
topic: 'settings',
subscriber: mySubscriber,
provider: myProvider,
applier,
});
await handle.start();
`
`typescript`
const applier = createZustandSnapshotApplier(store);
// Calls store.setState(partial) — non-destructive merge
`typescript`
const applier = createZustandSnapshotApplier(store, { mode: 'replace' });
// Calls store.setState(nextState, true) — atomic swap
- toState(data, ctx) — map snapshot data to state patchpickKeys
- / omitKeys — limit which keys are updatedstrict
- (default: true) — throw if toState` returns a non-object
See full documentation.