Skip to main content
skill CX Codex

tanstack-store · oakoss — Claude Code skill: what it does, how to install

A reference skill that teaches the agent how TanStack Store works: stores, derived values, batching, effects. Useful when state is shared across components.

MIT 113 installs ★ 29 updated 2026-08-17

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add oakoss/agent-skills --skill tanstack-store -a claude-code
Open on GitHub

What tanstack-store does

What the agent gets is a text cheat sheet for @tanstack/store, not a code generator: a pattern table covering new Store, setState, subscribe, new Derived, batch and new Effect, plus a mistakes table where each wrong move sits next to the right one. It comes into play when a task involves shared state, computed values or grouped updates.

Adjacent work is handed off. Server state and caching go to a separate tanstack-query skill, form state to tanstack-form; when neither is around, the agent points at npx skills add to fetch them.

One thing bites people: a Derived tracks nothing until mount() runs, and skipping the cleanup call leaves a subscription alive after teardown. On React, install @tanstack/react-store and leave the core package out — the adapter already re-exports Store, Derived, Effect and batch.

What it helps with

  • Keep a shared store updated without mutating state
  • Compute one value from several stores
  • Fold a run of updates into a single subscriber call
  • Run a side effect when a dependency changes
  • Pick the right adapter package for React, Vue or Svelte

Example prompts for the agent

  • Set up a shared @tanstack/store store for the cart plus a derived total.
  • That handler calls setState three times in a row — wrap it in batch so subscribers fire once.
  • derived.state stays stale after the update. Check the code and tell me what is missing around mount().

How to install tanstack-store

1Skills CLI (Vercel)

npx skills add oakoss/agent-skills --skill tanstack-store -a claude-code

2Manually: put the files in place

~/.claude/skills/tanstack-store/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/tanstack-store/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about tanstack-store

How do I install tanstack-store in Claude Code?

Run npx skills add oakoss/agent-skills --skill tanstack-store -a claude-code. The skill file lands at ~/.claude/skills/tanstack-store/SKILL.md.

What does tanstack-store do?

It hands the agent a compact guide to the TanStack Store API: creating a store, subscribing, derived values, effects and batching. Common mistakes such as reading derived.state before mounting are covered too.

Do I need both the core package and a framework adapter?

No. The React, Vue, Solid, Angular and Svelte packages re-export Store, Derived, Effect and batch, so one adapter is enough.

Source text

SKILL.md · MIT
---
name: tanstack-store
description: '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.'
license: MIT
metadata:
  author: oakoss
  version: '1.1'
  source: 'https://tanstack.com/store/latest'
user-invocable: false
---

# 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

| Package                   | Use Case                        |
| ------------------------- | ------------------------------- |
| `@tanstack/store`         | Framework-agnostic core         |
| `@tanstack/react-store`   | React adapter (re-exports core) |
| `@tanstack/vue-store`     | Vue adapter                     |
| `@tanstack/solid-store`   | Solid adapter                   |
| `@tanstack/angular-store` | Angular adapter                 |
| `@tanstack/svelte-store`  | Svelte adapter                  |

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

## Quick Reference

| Pattern              | API                                  | Key Points                                         |
| -------------------- | ------------------------------------ | -------------------------------------------------- |
| Create store         | `new Store(initialState, options?)`  | Generic over `TState` and `TUpdater`               |
| Read state           | `store.state`                        | Synchronous property access                        |
| Previous state       | `store.prevState`                    | Value before last `setState` call                  |
| Update state         | `store.setState((prev) => newState)` | Accepts updater function or direct value           |
| Subscribe            | `store.subscribe(listener)`          | Returns unsubscribe function                       |
| Derived value        | `new Derived({ deps, fn })`          | Lazily recomputes when dependencies change         |
| Mount derived        | `derived.mount()`                    | Required to activate dependency tracking           |
| Derived from derived | Nest `Derived` in another `deps`     | Forms a computation graph                          |
| Batch updates        | `batch(() => { ... })`               | Subscribers notified once after all updates        |
| Side effects         | `new Effect({ deps, fn, eager? })`   | Runs fn when dependencies change                   |
| Mount effect         | `effect.mount()`                     | Required to start listening                        |
| React binding        | `useStore(store, selector?)`         | Re-renders only when selected value changes        |
| Shallow compare      | `useStore(store, selector, shallow)` | Prevents re-renders for structurally equal objects |
| Lifecycle: subscribe | `onSubscribe` option                 | Fires on first subscriber, cleanup on last         |
| Lifecycle: update    | `onUpdate` option                    | Fires after every state change                     |
| Custom updater       | `updateFn` option                    | Replace default setState behavior                  |
| Previous deps        | `fn: ({ prevDepVals })`              | Compare current vs previous dependency values      |
| Dep vals access      | `fn: ({ currDepVals })`              | Array ordered by `deps` declaration order          |

## Common Mistakes

| Mistake                                           | Correct Pattern                                                       |
| ------------------------------------------------- | --------------------------------------------------------------------- |
| Reading `derived.state` without mounting          | Call `derived.mount()` before accessing state                         |
| Forgetting to unmount derived/effect              | Store the cleanup function and call it on teardown                    |
| Multiple `setState` calls without batching        | Wrap related updates in `batch()` to avoid intermediate recomputation |
| Selecting objects in `useStore` without `shallow` | Pass `shallow` as third argument to prevent unnecessary re-renders    |
| Mutating state object directly                    | Always return a new object from `setState` updater                    |
| Subscribing inside render without cleanup         | Use `useStore` hook in React instead of manual `subscribe`            |
| Creating stores inside React components           | Instantiate stores outside components or in a ref/useState            |
| Not including all deps in Derived                 | List every Store/Derived dependency in the `deps` array               |
| Mounting Derived deps after the parent            | Mount leaf dependencies before parent Derived values                  |
| Using `@tanstack/store` with React directly       | Install `@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

- [Core concepts: Store, setState, subscriptions, and lifecycle hooks](references/core-concepts.md)
- [Derived state: computed values, dependency tracking, and batching](references/derived-state.md)
- [React integration: useStore hook, selectors, and performance](references/react-integration.md)

© oakoss · MIT · oakoss/agent-skills

Similar skills

All skills for Frontend and UI →

tanstack-store by other authors comes first.

tanstack-store tanstack-skills A skill covering TanStack Store: a framework-agnostic reactive store with adapters for React, Vue, Solid, Angular and Svelte. Useful when your agent writes state with @tanstack/store. CX Codex +1 1,900installs tanstack-vue-store-skilld skilld-dev tanstack-vue-store-skilld — a skill for Claude Code that guides state management implementations using @tanstack/vue-store. Triggers whenever components import code from the library in a Vue application. CX Codex +1 100installs tanstack-vue-virtual-skilld skilld-dev The tanstack-vue-virtual-skilld skill guides Vue work with @tanstack/vue-virtual, from implementing virtual lists to debugging adapter usage. It also covers window scrolling and chat feeds anchored at the end. CX Codex +1 129installs tanstack-integration-best-practices DeckardGer tanstack-integration-best-practices — a skill that hands the agent rules for wiring TanStack Query, Router and Start together: loaders, SSR hydration, cache ownership. Useful once all three live in one codebase. CX Codex +1 3,100installs clerk-tanstack-patterns clerk The clerk-tanstack-patterns Claude Code skill covers Clerk authentication patterns for TanStack React Start. It activates for work with createServerFn, beforeLoad route protection, and request middleware. CX Codex +1 16,400installs tanstack-start tanstack-skills Guides agents through building full-stack React apps with TanStack Start, streaming SSR, and type-safe server functions. CX Codex +1 4,000installs tanstack-pacer tanstack-skills tanstack-pacer is a Claude Code skill for choosing utilities that control when functions run. It comes into play for debouncing, rate limits, queues, and batching. CX Codex +1 3,900installs

From the same set106

The whole set →
tanstack-cli tanstack-cli configures TanStack library build tooling, Vite dual ESM/CJS outputs, and conventional-commit publishing. CX Codex +1 115installs better-auth Hands the agent a reference for better-auth: config, plugins, session strategies and the usual mistakes. Useful when a project needs login, 2FA or multi-tenant organizations. CX Codex +1 114installs meta-skill-creator The meta-skill-creator skill guides you through building and validating agent skills that follow the Agent Skills open standard. Use it to plan a SKILL.md and organize supporting files. CX Codex +1 114installs figma-developer figma-developer pulls colours, type styles and icons out of Figma over the REST API and turns them into CSS variables and React components. Useful when the design file moves faster than your code. CX Codex +1 114installs hono Guides coding agents in building lightweight APIs, middleware pipelines, and RPC servers using the Hono framework. CX Codex +1 112installs astro Feeds the agent Astro patterns: content collections, island hydration, view transitions, rendering modes. Useful when most pages are static with a few interactive parts. CX Codex +1 111installs db-enforcer db-enforcer is a Claude Code skill that checks PostgreSQL integrity and alignment with Prisma. It activates for schema design, migration work, and RLS policy setup. CX Codex +1 109installs electricsql Briefs your coding agent on ElectricSQL: streaming slices of Postgres to the client through Shapes, plus the proxy and write patterns around it. CX Codex +1 109installs

Project sponsors

Companies that keep this analytics open