tanstack-store

TanStack Store for framework-agnostic reactive state management with derived state and batching. Use when managing shared state, creating derived computations, or building framework-agnostic state logic. Use for tanstack-store, store, state, derived, batch, subscribe, reactive-state.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "tanstack-store" with this command: npx skills add oakoss/agent-skills

TanStack Store

Overview

TanStack Store is a lightweight, framework-agnostic reactive state management library with type-safe updates, derived computations, batched mutations, and effect management. It powers the core of TanStack libraries internally and can be used as a standalone state solution. Framework adapters are available for React, Vue, Solid, Angular, and Svelte.

Core primitives:

  • Store — reactive container with setState, subscriptions, and lifecycle hooks
  • Derived — lazily computed values that track Store/Derived dependencies
  • Effect — side-effect runner triggered by dependency changes
  • batch — groups multiple updates so subscribers fire once

When to use: Shared reactive state across components, derived/computed values from multiple stores, batched state updates, framework-agnostic state logic reusable across React/Vue/Solid/Angular/Svelte, lightweight alternative to Redux/Zustand/MobX.

When NOT to use: Server state and caching (TanStack Query), complex normalized state with middleware (Redux Toolkit), form state management (TanStack Form), simple component-local state (useState/useSignal).

Key characteristics:

  • Tiny bundle size with zero dependencies
  • Immutable update model (always return new references from setState)
  • Lazy evaluation for Derived values (recompute only when accessed after change)
  • Explicit mount/unmount lifecycle for Derived and Effect (no automatic cleanup)

Installation

PackageUse Case
@tanstack/storeFramework-agnostic core
@tanstack/react-storeReact adapter (re-exports core)
@tanstack/vue-storeVue adapter
@tanstack/solid-storeSolid adapter
@tanstack/angular-storeAngular adapter
@tanstack/svelte-storeSvelte adapter

Framework packages re-export the core Store, Derived, Effect, and batch — install only the framework package, not both.

Quick Reference

PatternAPIKey Points
Create storenew Store(initialState, options?)Generic over TState and TUpdater
Read statestore.stateSynchronous property access
Previous statestore.prevStateValue before last setState call
Update statestore.setState((prev) => newState)Accepts updater function or direct value
Subscribestore.subscribe(listener)Returns unsubscribe function
Derived valuenew Derived({ deps, fn })Lazily recomputes when dependencies change
Mount derivedderived.mount()Required to activate dependency tracking
Derived from derivedNest Derived in another depsForms a computation graph
Batch updatesbatch(() => { ... })Subscribers notified once after all updates
Side effectsnew Effect({ deps, fn, eager? })Runs fn when dependencies change
Mount effecteffect.mount()Required to start listening
React bindinguseStore(store, selector?)Re-renders only when selected value changes
Shallow compareuseStore(store, selector, shallow)Prevents re-renders for structurally equal objects
Lifecycle: subscribeonSubscribe optionFires on first subscriber, cleanup on last
Lifecycle: updateonUpdate optionFires after every state change
Custom updaterupdateFn optionReplace default setState behavior
Previous depsfn: ({ prevDepVals })Compare current vs previous dependency values
Dep vals accessfn: ({ currDepVals })Array ordered by deps declaration order

Common Mistakes

MistakeCorrect Pattern
Reading derived.state without mountingCall derived.mount() before accessing state
Forgetting to unmount derived/effectStore the cleanup function and call it on teardown
Multiple setState calls without batchingWrap related updates in batch() to avoid intermediate recomputation
Selecting objects in useStore without shallowPass shallow as third argument to prevent unnecessary re-renders
Mutating state object directlyAlways return a new object from setState updater
Subscribing inside render without cleanupUse useStore hook in React instead of manual subscribe
Creating stores inside React componentsInstantiate stores outside components or in a ref/useState
Not including all deps in DerivedList every Store/Derived dependency in the deps array
Mounting Derived deps after the parentMount leaf dependencies before parent Derived values
Using @tanstack/store with React directlyInstall @tanstack/react-store which re-exports core

Delegation

  • Server state and caching: Delegate to the tanstack-query skill if available. Otherwise, recommend: npx skills add oakoss/agent-skills --skill tanstack-query
  • React component patterns: Delegate to framework-specific skills for component architecture
  • Form state management: Delegate to the tanstack-form skill if available. Otherwise, recommend: npx skills add oakoss/agent-skills --skill tanstack-form
  • Query pattern discovery: Use Explore agent to find examples in the codebase
  • Code review: Delegate to code-reviewer agent for store architecture review

References

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

playwright

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

ui-ux-polish

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

tanstack-form

No summary provided by upstream source.

Repository SourceNeeds Review