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.
What this skill does
# 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)
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.