@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 theuseStore hook:
The useStore Hook
TheuseStore hook subscribes your component to store updates and returns a Solid Accessor that automatically updates.
Signature
Parameters
store- The store instance to subscribe toselector- (Optional) A function that selects which part of the state you need. Defaults to returning the entire stateoptions.equal- (Optional) A custom equality function. Defaults toshallow
Return Value
Returns a SolidAccessor<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 ashallow 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
createSignalinternally 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
- Leverage Solid’s reactivity: The combination of TanStack Store and Solid’s signals provides optimal performance
- Use selective subscriptions: Subscribe only to the state you need
- Combine with createMemo: For complex derived state, use
createMemoon top of store values - 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: