agentleFS
FirzusFirzus/agent-skills/skills/web/tanstack-store/SKILL.md

tanstack-store

Skill4 starsChanged 20 days agoMITView on GitHub

TanStack Store client-state management. Use when implementing or reviewing @tanstack/store or its framework adapters, immutable updates, derived stores, selectors, subscriptions, batching, scoped SSR state, or migrations from legacy Store/Derived/Effect APIs.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read the installed core and adapter versions, lockfile resolutions, existing store definitions, and consumers before choosing an API.

    line 14
  2. Very specific:

    Keep update functions pure and synchronous.

    line 68
  3. Distinctive:

    After awaited work, batch only the synchronous writes that must notify together.

    line 115
  4. Distinctive:

    Legacy maintenance or an explicitly requested upgrade: read legacy.md; migrate lifecycle and consumers together.

    line 128
  5. Distinctive:

    Use the project's existing typecheck and nearest tests.

    line 140

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

TanStack Store

1. Establish the API generation and state owner

Read the installed core and adapter versions, lockfile resolutions, existing store definitions, and consumers before choosing an API. This skill's modern examples target core and React 0.11.1, verified on 2026-09-17. TanStack still labels Store alpha; resolve newer or intermediate versions against their installed declarations rather than assuming that all 0.x releases agree.

Evidence in the projectPath
Core 0.11.1, React 0.11.1Use the modern examples below.
Core 0.9–0.10Signals rewrite, but newer adapter hooks may be absent; verify exports.
Core through 0.8, explicit Derived / EffectRead legacy.md before changing code.
Multiple core versions, including transitive dependenciesFollow the package resolved by each consumer; retain unrelated library internals.

Choose ownership before adding a store:

StatePreferred owner
One component's temporary UI stateFramework-local state
Shared client-owned state or reactive calculationsTanStack Store
Shareable navigation, filters, paginationRouter URL/search state
Remote data, freshness, retries, mutationsExisting server-state cache, such as TanStack Query
Synchronized collections and relational live queriesExisting data layer, such as TanStack DB

Finish this step with the resolved API generation, state owner, store lifetime, and affected consumers identified. Preserve the project's existing state layer unless the requested behavior needs a change.

2. Implement the state transition

createStore(value) creates writable state. setState(updater) replaces the whole value with the updater's return value; it does not merge object fields. Return new references along changed paths and retain unchanged branches.

import { createStore } from '@tanstack/store'

type Filters = {
  query: string
  status: 'all' | 'open' | 'closed'
}

export function createFiltersStore() {
  const store = createStore<Filters>({ query: '', status: 'all' })

  function setQuery(query: string) {
    store.setState((state) =>
      state.query === query ? state : { ...state, query },
    )
  }

  return { store, setQuery }
}

Keep update functions pure and synchronous. Use an explicit state type for unions, nullable values, and empty collections. Core change detection uses Object.is; mutating an object and returning the same reference can suppress notifications. A direct .state or .get() read returns a snapshot, not a UI subscription.

Reuse ordinary action functions like the example. When the installed API and project use createStore(initialValue, actionsFactory), actions are exposed through .actions; this is optional, not a reason to restructure existing stores.

Finish when each requested transition preserves unrelated state and has one authoritative write path.

3. Derive and observe

createStore(getter) creates a readonly computed store. Reads of other stores inside its synchronous getter establish dependencies automatically, including conditional dependencies. Read dependencies inside the getter rather than closing over snapshots read beforehand.

import { batch, createStore } from '@tanstack/store'

const price = createStore(10)
const quantity = createStore(2)
const total = createStore(() => price.state * quantity.state)
const observedTotals: number[] = []
const subscription = total.subscribe((value) => observedTotals.push(value))

batch(() => {
  price.setState(() => 12)
  quantity.setState(() => 3)
})

subscription.unsubscribe()

The final total is 36; the subscription receives that update, not an initial value. Read .state separately when an initial snapshot is needed.

  • Modern computed stores need no .mount(). Keep getters pure: evaluation is lazy and subscription-driven, not an event log. A getter's optional previous value is the previous computation result, not a guarantee to process every write.
  • subscribe receives the new value and returns { unsubscribe }. Attach its cleanup to the owner's disposal/unmount lifecycle; use it for external effects.
  • batch delays notifications until the outermost synchronous batch ends. Writes still happen immediately; it is neither rollback nor an async transaction. After awaited work, batch only the synchronous writes that must notify together.
  • Store computations track Store reads, not arbitrary framework props. Bridge changing inputs explicitly through the existing framework integration.

Finish when derived values have no duplicated writable copy and every manual subscription has a cleanup owner.

4. Connect the framework and lifetime

  • React selectors, component-owned stores, context, SSR, or persistence: read react.md. Subscribe to the slice rendered by the component.
  • Other frameworks: inspect the adapter's official quick start and installed types. Vue refs, Solid accessors, Svelte .current, and Angular signals are different return contracts.
  • Legacy maintenance or an explicitly requested upgrade: read legacy.md; migrate lifecycle and consumers together.
  • Atoms, async atoms, action factories, devtools, or disputed API behavior: inspect the installed implementation and matching official documentation before extending it. Verify exports; custom persistence and request caching are not implicit Store capabilities.

Finish when the store survives the intended renders, is disposed at the right boundary, and cannot leak request-specific state between server requests.

5. Validate the changed contract

Use the project's existing typecheck and nearest tests. Cover the paths changed:

  • Consecutive updates use the latest state and preserve unrelated fields.
  • A changed nested value gets new references; a no-op preserves its reference.
  • Derived results update when active dependencies change, including branch switches.
  • Batched writes expose the expected final notification; cleanup stops observation.
  • A component reacts to its selected slice, including prop-dependent selectors; unrelated writes do not cause store-driven rerenders when selection is equal.
  • Scoped instances remain independent; SSR hydration starts from matching data.

Report the resolved versions, checks run, and any untested runtime boundary.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.