Skip to main content

Reference

useStore

A Svelte 5 function that subscribes to a TanStack Store atom using runes and returns a reactive object with a current property. The value 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 current: TSelected }
A reactive object with a readonly current property containing the selected state value.

Usage

Basic Usage

Selecting Multiple Values

Custom Equality Function

Using Entire State

With Conditional Rendering

With Each Blocks

Derived Values

Selecting Array Slices

Notes

  • Built for Svelte 5 using the new runes system ($state, $effect)
  • Returns an object with a readonly current property
  • Uses $state rune internally for reactivity
  • Automatically cleans up subscriptions using $effect cleanup
  • Defaults to shallow equality comparison
  • Access the value via .current property
  • Compatible with Svelte’s reactive declarations and derived values
  • Works seamlessly with {#if}, {#each}, and other Svelte control flow