Skip to main content
TanStack Store provides Solid support through the @tanstack/solid-store package, which integrates seamlessly with Solid’s fine-grained reactivity system.

Installation

Install the Solid adapter package:
The @tanstack/solid-store package re-exports everything from @tanstack/store, so you only need to install the Solid package.

Basic Usage

The primary way to use TanStack Store in Solid is through the useStore hook:

The useStore Hook

The useStore hook subscribes your component to store updates and returns a Solid Accessor that automatically updates.

Signature

Parameters

  • store - The store instance to subscribe to
  • selector - (Optional) A function that selects which part of the state you need. Defaults to returning the entire state
  • options.equal - (Optional) A custom equality function. Defaults to shallow

Return Value

Returns a Solid Accessor<TSelected> (a function that returns the selected state). Call it like count() to get the current value.

Selector Optimization

The selector function allows you to subscribe to only the parts of state you need:

Custom Equality Functions

For complex state selections, provide a custom equality function:

Shallow Equality

The package exports a shallow utility for shallow object comparison (this is the default):

Complete Example: Todo App

Here’s a complete Todo application using Solid:

Solid-Specific Considerations

Fine-Grained Reactivity

The Solid adapter leverages Solid’s fine-grained reactivity:
  • Uses createSignal internally to track changes
  • Automatically cleans up with onCleanup
  • Integrates with Solid’s reactive primitives (createMemo, createEffect, etc.)

Working with Solid’s Reactivity

You can use store values in Solid’s reactive primitives:

Server-Side Rendering (SSR)

TanStack Store works with SolidStart and SSR:

Performance Tips

  1. Leverage Solid’s reactivity: The combination of TanStack Store and Solid’s signals provides optimal performance
  2. Use selective subscriptions: Subscribe only to the state you need
  3. Combine with createMemo: For complex derived state, use createMemo on top of store values
  4. Multiple stores: Create focused stores for different domains

Derived Stores

Create derived stores that react to other stores:

Combining with Solid Store

You can use TanStack Store alongside Solid’s built-in store if needed:

API Reference

For detailed API documentation, see:
  • See the API reference for detailed documentation:

TypeScript Support

The Solid adapter provides full TypeScript support: