Skip to main content

Reference

useStore

A Vue composable that subscribes to a TanStack Store atom and returns a readonly ref. The ref will update when the selected state changes according to the equality function.
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 watch API to track store subscriptions
  • Automatically cleans up subscriptions when the component is unmounted
  • Defaults to shallow equality comparison to optimize reactivity
  • Uses toRaw to unwrap Vue proxies before comparison
  • Compatible with both Vue 2 (via vue-demi) and Vue 3