Documentation Index
Fetch the complete documentation index at: https://mintlify.com/TanStack/store/llms.txt
Use this file to discover all available pages before exploring further.
Reference
useStore
The store atom to subscribe to. Can be
undefined to support conditional usage.A function that selects a slice of state from the atom’s snapshot. Use this to optimize re-renders by selecting only the data your component needs.
Optional comparison function to determine if the selected state has changed. Defaults to reference equality (
Object.is). Use shallow for shallow object comparison.Returns
The selected state value from the atom.
Usage
Basic Usage
With Custom Comparison
Selecting Multiple Values
Notes
- Built on top of React’s
useSyncExternalStoreWithSelectorfor optimal concurrent rendering support - Automatically handles subscription cleanup when the component unmounts
- The selector function should be stable or memoized to avoid unnecessary re-subscriptions
- Supports
undefinedatoms for conditional store usage - Uses reference equality by default - provide a custom compare function for object comparisons