Reference
useStore
Atom<TState> | ReadonlyAtom<TState>
The store atom to subscribe to.
(state: TState) => TSelected
default:"(d) => d"
Optional function that selects a slice of state from the atom. Defaults to returning the entire state.
UseStoreOptions<TSelected>
Optional configuration object.
Returns
Readonly<Ref<TSelected>>
A readonly Vue ref containing the selected state value.
Usage
Basic Usage
Selecting Multiple Values
Custom Equality Function
Using Entire State
With Computed Properties
Notes
- Returns a readonly ref - the value cannot be mutated directly
- Uses Vue’s
watchAPI to track store subscriptions - Automatically cleans up subscriptions when the component is unmounted
- Defaults to
shallowequality comparison to optimize reactivity - Uses
toRawto unwrap Vue proxies before comparison - Compatible with both Vue 2 (via vue-demi) and Vue 3