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 exports a collection of utility functions alongside its store creators. These helpers cover store introspection, equality checking, time conversion, JSON serialization of non-plain types, low-level state updates, and query constants.
Store Inspection
These functions let you inspect and tear down stores at runtime. They work with any store type — base stores, derived stores, query stores, persisted stores, and virtual stores.destroyStore
- For query stores, calls
store.getState().reset(clearQueryCache). - For derived stores (which expose
destroy), callsstore.destroy(). - For all other stores, this is a no-op — base stores have no teardown by default.
The store to destroy.
When
true and the store is a query store, the query cache is also cleared in
addition to resetting fetch state.destroyStores
destroyStore on each. Useful for tearing down a feature’s entire set of stores in one call.
An array or plain-object record of store instances.
undefined entries in
arrays are silently skipped.Forwarded to
destroyStore for each query store encountered.Predicate called for each store. When it returns
true, that store is skipped.getStoreName
name from the persistence options. For all other stores, returns the function’s .name property (i.e. the variable name the store was assigned to at creation time).
isDerivedStore
true when the store was created with createDerivedStore. Narrows the type to reveal destroy() and flushUpdates().
isQueryStore
true when the store was created with createQueryStore.
isPersistedStore
true when the store has an active persist configuration. Narrows the type to expose the full persist API.
isVirtualStore
true when the store was created with createVirtualStore.
hasGetSnapshot
true when the store exposes a getSnapshot method. Derived stores use getSnapshot to read current state while activating lazy subscriptions before the first subscriber attaches.
Equality Functions
shallowEqual
Object.is. For non-objects, falls back to strict equality. Returns true when all top-level key/value pairs are identical.
Use shallowEqual as the equalityFn for selectors that return a new object reference on every call (e.g. state => ({ a: state.a, b: state.b })). Without it, every state change would appear as a new value even when the contents are the same.
Worklet-compatible — safe to use inside React Native Reanimated worklets.
deepEqual
deepEqual for nested structures where shallowEqual would miss differences inside nested objects. Note that deepEqual is more expensive than shallowEqual — prefer shallowEqual when your state shape is shallow.
Worklet-compatible — safe to use inside React Native Reanimated worklets.
Time Utility
time
time.infinity and time.zero are plain constants.
time methods include a 'worklet' directive and are safe to call inside Reanimated worklets.
Query Param Helper
queryParam
The parameter value or a reactive getter that produces the value.
Controls how this parameter participates in the query key:
false— exclude this parameter from the query key entirely.(value: T) => unknown— a function that returns the key representation of the value (e.g. extracting anidfrom a full object).
Serialization
These functions areJSON.stringify/JSON.parse replacer and reviver pairs that add support for Map and Set values. Pass them as serializer/deserializer in your persistence config when your store state contains non-plain JavaScript types.
replacer
JSON.stringify replacer that converts Map instances to { __type: 'Map', entries: [...] } and Set instances to { __type: 'Set', values: [...] }.
reviver
JSON.parse reviver that reconstructs Map and Set instances from the tagged objects written by replacer.
State Update
applyStateUpdate
setState without touching a store:
- If
replaceistrue, returns the update directly (or calls it as a function with the current state). - Otherwise, merges the partial update into the current state shallowly.
- Returns the original
statereference unchanged when the update produces no diff (Object.ischeck).
Error Handling
StoresError
name property is always 'StoresError'. When an underlying error caused the failure, it is available as cause.
Use instanceof StoresError in error boundaries or error handlers to distinguish framework errors from application errors:
Query Constants
QueryStatuses
QueryStatus value. Prefer these constants over raw string literals when branching on query state:
defaultRetryDelay
baseDelay (default 5s), doubles on each retry, and is capped at maxDelay (default 5m):
retryDelay that extends the default behaviour: