Skip to main content

Framework Agnostic Reactive Store

Type-safe state management with fine-grained reactivity. Build reactive applications with atoms, derived stores, and framework adapters for React, Vue, Solid, Angular, Svelte, and Preact.

Quick Start

Get up and running with TanStack Store in minutes

1

Install the package

Choose your preferred package manager to install TanStack Store:
npm install @tanstack/store
For framework-specific adapters, install the corresponding package (e.g., @tanstack/react-store, @tanstack/vue-store).
2

Create your first store

Import createStore and initialize a store with an initial value:
import { createStore } from '@tanstack/store'

const countStore = createStore(0)

console.log(countStore.state) // 0
Stores can hold any JavaScript value: primitives, objects, arrays, or complex nested structures.
3

Subscribe to changes

Subscribe to store updates to react to state changes:
const { unsubscribe } = countStore.subscribe(() => {
  console.log('Count changed:', countStore.state)
})

countStore.setState(() => 1)  // Logs: "Count changed: 1"
countStore.setState(() => 2)  // Logs: "Count changed: 2"

// Cleanup when done
unsubscribe()
4

Use with your framework

For React, Vue, Solid, Angular, Svelte, or Preact, use the framework-specific adapter:
import { useStore } from '@tanstack/react-store'

function Counter() {
  const count = useStore(countStore, (state) => state)
  
  return (
    <button onClick={() => countStore.setState((c) => c + 1)}>
      Count: {count}
    </button>
  )
}
See the Framework Guides for complete integration examples.

Explore by Topic

Learn core concepts and integrate with your favorite framework

Stores

Create reactive stores to manage application state

Atoms

Build fine-grained reactive primitives with atoms

Derived Stores

Compute values automatically from other stores

Subscriptions

React to state changes with subscriptions

Batching

Optimize performance with batched updates

Async Atoms

Handle asynchronous data with async atoms

Key Features

Built for performance, developer experience, and flexibility

Fine-Grained Reactivity

Update only what changes with fine-grained subscriptions. No unnecessary re-renders or computations.

Type-Safe

Full TypeScript support with inference. Catch errors at compile time, not runtime.

Framework Agnostic

Use vanilla JS or any framework. Adapters for React, Vue, Solid, Angular, Svelte, and Preact included.

Lightweight

Minimal bundle size with zero dependencies. Only pay for what you use.

Ready to build reactive applications?

Get started with TanStack Store in minutes and experience the power of fine-grained reactivity.

Get Started