These hooks are part of the React build ofDocumentation 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 and are not available in the vanilla (framework-agnostic) build. Import them from @storesjs/stores in any React or React Native project.
useListen
useListen subscribes to a slice of a store and runs a callback whenever that slice changes — without causing the component to re-render. It is the right tool when you need to react to state changes imperatively: forwarding values to Reanimated shared values, triggering side effects, or deciding yourself whether and when a render should occur.
The hook attaches the subscription automatically on mount and removes it on unmount. Use the returned ListenHandle only when you need to pause or resume the listener manually.
Signature
Parameters
The store to subscribe to. Should be a stable reference — the hook re-attaches
when this value changes.
Selects the slice of store state to observe. The
react callback is only
invoked when this selected value changes according to equalityFn.Callback fired whenever the selected slice changes. Receives the current
value, the previous value, and a convenience
unsubscribe function that
permanently detaches this listener.Either a
UseListenOptions config object or a shorthand equality function.
When omitted, defaults apply.Return value
A React ref whose
.current value is a ListenHandle:Example
The following pattern is taken directly from the source docblock. It forwards candlestick data to a Reanimated chart manager without ever re-rendering the component:The hook manages its own lifecycle — you do not need to call
unsubscribe in
a cleanup function. Only reach for the returned ListenHandle when you want
to explicitly pause the listener (e.g. while a long-lived component is
off-screen) and later resume it with resubscribe().useStableValue
useStableValue runs an initializer function exactly once per component instance and returns the same value for the lifetime of that component. It is a safe, idiomatic alternative to useRef + manual initialization guards for expensive or stateful values that must not be recreated on re-renders.
Signature
Parameters
A zero-argument factory function. It is called only on the first render
of a given component instance. Subsequent renders skip the call entirely and
return the cached value.
Return value
The stable value produced by
init on the first render.