@statesync/zustand
v2.0.0
Published
Zustand adapter for state-sync — automatic store synchronization
Downloads
185
Maintainers
Readme
@statesync/zustand
Zustand adapter for state-sync. Applies snapshots to a Zustand store.
Install
npm install @statesync/zustand @statesync/coreQuick Start
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();Modes
Patch (default)
const applier = createZustandSnapshotApplier(store);
// Calls store.setState(partial) — non-destructive mergeReplace
const applier = createZustandSnapshotApplier(store, { mode: 'replace' });
// Calls store.setState(nextState, true) — atomic swapOptions
toState(data, ctx)— map snapshot data to state patchpickKeys/omitKeys— limit which keys are updatedstrict(default:true) — throw iftoStatereturns a non-object
See full documentation.
