Documentation Index
Fetch the complete documentation index at: https://mintlify.com/christianbaroni/stores/llms.txt
Use this file to discover all available pages before exploring further.
@storesjs/stores is written in TypeScript and exports all of its public types. This reference documents each exported type grouped by concern, showing the exact definition from source so you can use them confidently in your own type annotations.
Store Types
Store<S, PersistedState?, PersistReturn?>
The top-level convenience union that resolves to either a BaseStore or a PersistedStore depending on whether PersistedState is provided.
BaseStore<S>
A store without persistence. Combines Zustand’s StoreApi<S> with React hook call signatures and a typed subscribe overload.
BaseStore as a function is the React hook interface — store(), store(selector), and store(selector, equalityFn) are all valid call signatures.
PersistedStore<S, PersistedState, PersistReturn>
Extends BaseStore<S> with a persist namespace that exposes hydration, storage management, and option inspection.
persist object exposes:
Removes the persisted entry from storage.
Returns the resolved persistence options.
Returns
true once the store has been hydrated from storage.Registers a listener that fires when hydration begins. Returns an unsubscribe function.
Registers a listener that fires when hydration completes. Returns an unsubscribe function.
Manually triggers re-hydration from storage.
Updates persistence options at runtime.
Available only on async-persisted stores. Returns a promise that resolves once hydration completes.
DerivedStore<Derived>
A read-only store produced by createDerivedStore. The setState and getInitialState methods are deprecated on this type (they throw at runtime). Adds destroy() and flushUpdates().
Destroys the derived store and its internal subscriptions. Usually unnecessary
since derived stores self-clean when all subscribers leave, unless
keepAlive: true was specified.Immediately flushes any pending debounced updates. Only applicable to derived
stores created with the
debounce option.OptionallyPersistedStore<S, PersistedState, PersistReturn>
Used by store creators that accept optional persistence configuration. The persist namespace is present only when a storageKey is supplied.
StoreActions<Store>
Picks all function-typed keys from a store’s state type. This is the return type of createStoreActions.
InferStoreState<Store>
Extracts the state type S from any store that has a getState method.
InferPersistedState<Store>
Extracts the PersistedState type from a persisted store. Returns never for non-persisted stores.
InferSetStateReturn<Store>
Extracts the return type of a store’s setState method — void for synchronous stores, Promise<void> for async-persisted stores.
Persistence Types
PersistConfig<S, PersistedState, PersistReturn>
All options accepted when configuring persistence for a store.
The unique key under which the store’s state is persisted.
Schema version number. When the persisted version differs from this value,
migrate is called.Returns the subset of state to persist. Defaults to the entire state.
Custom merge strategy for hydration. Defaults to a shallow merge.
Called when the stored version does not match
version.A function called before hydration. May return a callback that is invoked
after hydration completes or when an error occurs.
Custom serializer. Defaults to the storage adapter’s serializer, then
JSON.stringify.Custom deserializer. Defaults to the storage adapter’s deserializer, then
JSON.parse.Override the global storage adapter for this specific store.
Throttle rate for write operations in milliseconds. Not applicable to async
stores. Defaults to 3 s on iOS and 5 s on Android.
StorageValue<S, HideSyncMetadata?>
The shape of the value stored in and read from storage by the persistence layer.
StorageValue<PersistedState> (with HideSyncMetadata defaulting to false) in custom serializer and deserializer functions to get the full value including optional sync metadata. When HideSyncMetadata is true, the syncMetadata field is omitted from the type — useful when you know your store does not use sync.
SyncStorageInterface<SerializedState>
Contract for synchronous storage adapters such as localStorage or MMKV.
AsyncStorageInterface<SerializedState>
Contract for asynchronous storage adapters such as Chrome extension storage.
async: true discriminant allows the framework to detect at runtime whether a storage adapter is synchronous or asynchronous and adjust the setState return type accordingly.
Query Store Types
QueryStoreConfig<TQueryFnData, TParams, TData, CustomState>
Full configuration accepted by createQueryStore. See configureStores for the subset of these fields that can be set as global defaults via queryStoreDefaults.
Key fields:
fetcher
(params: TParams, abortController: AbortController | null) => TQueryFnData | Promise<TQueryFnData>
required
The async function responsible for loading remote data.
Static, reactive, or
queryParam-wrapped parameters forwarded to fetcher.How long fetched data is considered fresh before background refetching may occur.
How long a cache entry is retained before pruning.
Whether the store actively fetches. Can be a static boolean or a reactive
getter.
Transforms raw fetcher output into the shape stored in the cache. Required
when
TData differs from TQueryFnData.Callback invoked after every successful fetch.
Callback invoked after every failed fetch attempt.
Overrides the default behaviour of writing fetched data into the internal
query cache.
Maximum number of automatic retry attempts after a fetch failure.
Delay between retry attempts. Defaults to exponential backoff.
When
true, getData() returns stale data while a new fetch is in flight.When
true, fetched data is not written to the internal cache.When
true, stale data is not automatically refreshed in the background.When
true, in-flight fetches are aborted when parameters change or all
subscribers unmount.Delay before triggering a fetch in response to parameter changes.
Enables verbose console logging for this store.
Suppresses the development warning emitted when
staleTime is shorter than
minStaleTime.QueryStoreState<TData, TParams, CustomState>
The full runtime state managed by a query store. Includes all internal state keys plus any custom state fields.
Current fetch status:
'idle', 'loading', 'success', or 'error'.Whether the store is actively fetching.
The most recent fetch error, or
null.Timestamp of the last successful fetch.
Internal map of cache entries keyed by generated query key strings.
The deterministic query key built from current parameters.
Imperatively trigger a fetch. See
FetchOptions for available options.Returns cached data for the given parameters or query key.
Returns the full cache entry (data + metadata) for the given key.
Returns expanded status flags. Pass a
keyof QueryStatusInfo to retrieve a
single flag.Returns
true when the current data has exceeded staleTime.Returns
true when the current cache entry has exceeded cacheTime.Tears down param subscriptions and timers. Optionally resets all state.
QueryStatus
QueryStatuses constants object to avoid raw string comparisons.
QueryStatusInfo
getStatus().
CacheEntry<T>
A cache entry storing fetched data alongside fetch metadata and optional error information.
FetchOptions
Options accepted by the fetch method on a query store’s state.
Forces a fetch even when fresh data is available in the cache.
Overrides the store’s
staleTime for this specific fetch call.Overrides the store’s
cacheTime for the data fetched in this call.When
true, the fetch runs silently without updating store state. When
'withCache', the result is written to the cache but store state is
otherwise untouched.Whether to update the store’s
queryKey to reflect the params used in
this fetch. Defaults to false for manual fetches.When
true, the returned promise rejects on fetch failure instead of
updating store error state silently.QueryParam<T, State>, ReactiveParam<T, State>, QueryParamConfig<T, State>
Sync Types
FieldMetadata
Metadata recorded for each synced field write. A tuple of the write timestamp and the originating session ID.
SyncStateKey<T>
Extracts only the non-function keys from a store state type T. These are the keys that can be included in SyncConfig.fields and used as sync targets.
SyncValues<T>
A partial object of the non-function state keys of T. This is the type of values in a SyncUpdate.
SyncConfig<T>
Options for enabling cross-client sync on a store.
Identifier shared across clients to target the same store. Required when
the store is not persisted (no
storageKey to fall back on).The specific state keys to synchronize. Defaults to all non-function
properties.
Override the global sync engine for this store.
Per-field merge functions for conflict resolution. Use with caution.
When
true, sync metadata is embedded in the storage payload. Required for
engines that use storage writes as their transport (e.g. chrome.storage).SyncEngine interface
Interface for pluggable multi-client synchronization.
A unique identifier for this client session, used for conflict resolution and
self-update filtering.
When
true, the engine requires sync metadata to be embedded in persisted
storage values.Connects a store to the sync system. Returns a
SyncHandle to manage the
sync lifecycle.SyncHandle<T> interface
Returned by SyncEngine.register(). Controls the lifecycle of a synced store.
Permanently removes this store from the sync engine.
Broadcasts a state update to other clients.
null for engines where
publishing is implicit (e.g. chrome.storage).Returns
true once the store has received its initial state from the engine.Called when the store’s subscriber count goes from 0 to 1. Use for lazy
resource acquisition (e.g. opening a WebSocket).
Called when the store’s subscriber count drops to 0. Use for resource cleanup.
Registers a one-time callback fired when hydration completes.
SyncRegistration<T>
Passed to SyncEngine.register() to describe the store being registered.
SyncUpdate<T>
The payload broadcast between clients when state changes.
Derive Types
DeriveGetter
The $ argument received inside a createDerivedStore callback. Two overloads are available:
DeriveOptions<Derived>
Configuration for createDerivedStore. Can be passed as a plain equality function or as a config object.
Adds a debounce delay before the derive function re-runs when dependencies
change. Accepts a plain number (ms) or a full
DebounceOptions object for
leading/trailing/maxWait control.When
true, logs dependency subscriptions on the first derivation run. When
'verbose', logs on every run.Custom equality check to suppress downstream updates when the derived value
has not meaningfully changed.
When
true, the derived store never self-destructs even when subscriber
count drops to zero.When
true, the dependency graph is fixed after the first derivation.
Subscriptions are established once and reused, avoiding subscription churn.
Safe when all $ calls are unconditional and top-level.Hook Types
ListenHandle
useListen as a ref. See the Hooks reference for full usage details.
UseListenOptions<Selected>
useListen. See the Hooks reference for default values and reactive behaviour notes.