Use this file to discover all available pages before exploring further.
createBaseStore is the foundational store factory in @storesjs/stores. It creates a local, synchronous store from a state creator function and returns a store object that exposes getState, setState, subscribe, and getInitialState. When a storageKey is provided through the options, the store also gains a .persist namespace with hydration and storage-management utilities. In the React build the returned store is also callable as a hook, letting you subscribe to a slice of state with an optional selector and equality function.
The PersistReturn type parameter controls whether setState is synchronous (void) or asynchronous (Promise<void>), which is inferred automatically from the storage adapter you provide.
Updates the store’s state. Accepts a partial state object, a full state replacement object (when replace is true), or an updater function that receives the current state and returns an updated slice.
The raw store object. Gives you access to getState, setState, and subscribe from within the state creator, which can be passed to utilities or closures that need a stable store reference.
Optional configuration object. Accepts the PersistConfig fields below plus an optional sync field. Providing storageKey activates persistence and adds .persist to the returned store.
The unique key used to read and write state in the configured storage backend. Required when persistence is enabled. Changing this key between app versions effectively resets the persisted state.
A function that receives the full state and returns only the slice that should be written to storage. By default the entire state object is persisted. Use this to exclude transient or derived fields.
partialize: state => ({ currency: state.currency })
The current schema version. When the version stored on disk differs from this value, migrate is called before the persisted state is merged into the store.
An optional migration function invoked when the persisted schema version does not match version. Receives the raw persisted state and the version it was saved with. Should return the migrated state. May be async.
(persistedState: PersistedState | undefined, currentState: S) => S
Controls how the persisted snapshot is merged into the in-memory state during hydration. By default a shallow merge is performed. Override this when you need deep merging or special handling of collections.
A callback invoked before hydration begins. The function it returns (if any) is called after hydration completes or when an error occurs, receiving the final state and any error that was thrown.
Custom serialization function. Converts the internal StorageValue envelope (which includes the state and schema version) into a string for storage. Defaults to JSON.stringify after the storage adapter’s own serializer is applied.
Custom deserialization function. The inverse of serializer; converts a raw stored value back into the StorageValue envelope. Defaults to JSON.parse after the storage adapter’s own deserializer is applied.
The storage backend to use. Supply a SyncStorageInterface (e.g. localStorage, MMKV) to keep setState synchronous. Supply an AsyncStorageInterface (e.g. Chrome storage, async MMKV) to make setState return Promise<void>. When omitted the default platform storage is used.
Throttle interval in milliseconds between successive writes to storage. Helps reduce I/O pressure when state changes rapidly. Defaults to time.seconds(3) on iOS and time.seconds(5) on Android. Only valid for synchronous storage — set to undefined for async storage.
Enables cross-tab or cross-context state synchronization. Pass true to inherit the sync key from storageKey, a plain string to use a custom key, or a SyncConfig object for full control. This option is a sibling of the PersistConfig fields, not nested inside them.
createBaseStore returns a Store<S> (non-persisted) or Store<S, PersistedState, PersistReturn> (persisted). Both variants expose the same core store API.
Merges a partial state update into the current state. When replace is true, the second overload replaces the entire state object. For stores backed by async storage, returns a Promise<void> that resolves once the state has been written to disk.
Fires listener only when the value returned by selector changes according to equalityFn. Useful for subscribing to a single field without reacting to unrelated changes.
Returns the initial state object produced by createState at construction time, before any setState calls. Useful for resetting a store to its defaults.
Available only for async storage backends. Returns a promise that resolves once the initial hydration pass has finished. Useful for awaiting hydration in setup or test code.
In the React build every store is also callable as a hook:
// Subscribe to the full stateconst state = store();// Subscribe to a selected sliceconst currency = store(s => s.currency);// Subscribe with a custom equality functionconst items = store(s => s.items, shallowEqual);
Calling the store as a hook inside a component automatically subscribes to the selected state and triggers a re-render when it changes.