tanstack/db/react-db
Claude Code and agent skill by tanstack/db
- community
Checking that the SKILL.md file is still in the repository.
React bindings for TanStack DB. Prefer useLiveQuery({ query }) with derived structured query identity. Provide queryKey only for opaque functional query variants or very hot render paths. Dependency arrays are legacy and warn before 1.0 removal. useLiveSuspenseQuery for React Suspense with Error Boundaries (data always defined). useLiveInfiniteQuery for cursor-based pagination (pageSize, fetchNextPage, hasNextPage, isFetchingNextPage). usePacedMutations for debounced React state updates. Return shape: data, state, collection, status, isLoading, isReady, isLoadingError, isCrashed, isSyncError, health. Import from @tanstack/react-db (re-exports all of @tanstack/db).
Install
npx vskill@latest install tanstack/db/react-dbSKILL.md
The same SKILL.md was published earlier as tanstack/db/react-db.
This skill builds on db-core. Read it first for collection setup, query builder, and mutation patterns.
TanStack DB — React
Setup
@tanstack/react-db re-exports everything from @tanstack/db. In React projects, import everything from @tanstack/react-db.
Hooks
useLiveQuery
isLoadingError means the first load failed and there is nothing to show; offer collection.reload(). isCrashed means local storage broke; only cleanup({ dependents: true }) and a fresh start recover. After the query is ready, sync problems never change status: read isSyncError or the health tree to show stale-data warnings. isError and node phase were removed.
Many queries of one shape, such as one per list row, can share one partition. Pass pool: pooledLiveQueries (from @tanstack/db) in the config form: useLiveQuery({ query, pool: pooledLiveQueries }). Pooling applies to queries that filter one eager source with eq(field, literal). It is off by default, and Suspense and DbClient queries never pool.
useLiveSuspenseQuery
useLiveInfiniteQuery
usePacedMutations
Includes (Hierarchical Data)
When a query uses include() for a subquery in select, each child field is a live Collection. Subscribe to it with useLiveQuery in a subcomponent:
Only the affected IssueList re-renders when an issue changes — the parent does not.
With toArray(), child results are plain arrays and the parent re-renders on child changes:
See db-core/live-queries/SKILL.md for full includes rules (correlation conditions, nested includes, aggregates).
Virtual Properties
Live query results include computed, read-only virtual properties on every row:
$hasPendingWrites:truewhile a pending local optimistic write affects
the row; false otherwise. It does not prove backend confirmation.
$origin:"local"if the last confirmed change came from this client, otherwise"remote".$key: the row key for the result.$collectionId: the source collection ID.
These props are added automatically and can be used in where, select, and orderBy clauses. Do not persist them back to storage.
React-Specific Patterns
Query identity
Use queryKey only when DB cannot derive identity from structured IR, such as .fn.where, .fn.select, .fn.having, or as a deliberate performance escape hatch on a hot render path:
Unhashable IR without queryKey throws UnhashableQueryIRError, even with a dependency array. Slow or repeated derived identity work warns once and points to the same queryKey escape hatch.
Suspense + Error Boundary
Router loader preloading
See meta-framework/SKILL.md for full preloading patterns.
Common Mistakes
CRITICAL Using === instead of eq() in .where()
Wrong — throws InvalidWhereExpressionError at runtime:
Correct — use expression functions from @tanstack/react-db:
JavaScript ===, !==, <, and > evaluate immediately and return a boolean. Use expression functions such as eq, gt, gte, lt, lte, and, or, and not for structured .where() predicates. See db-core/live-queries/SKILL.md for the full operator reference.
CRITICAL Assigning useLiveQuery result directly instead of destructuring
Wrong — crashes with "map is not a function":
Correct — destructure { data }:
useLiveQuery returns an object with data, isLoading, status, and other fields. For queries that can be disabled, use { data: todos = [] } to handle data being undefined.
CRITICAL Using opaque query logic without queryKey
Wrong:
Correct:
Structured expressions are hashable by default. Functional query variants are opaque runtime code, so they need an explicit key to say when identity changes.
Source: docs/framework/react/overview.md
HIGH useLiveSuspenseQuery without Error Boundary
Wrong:
Correct:
useLiveSuspenseQuery throws errors during rendering. Without an Error Boundary, the entire app crashes.
Source: docs/guides/live-queries.md
HIGH "Not a Collection" error from duplicate @tanstack/db
If a query-builder alias throws InvalidSourceError: The value provided for alias "todo" is not a Collection, it can mean two copies of @tanstack/db are installed. Direct useLiveQuery(preCreatedCollection) detection is structural and works across package copies or realms, but q.from({ todo: collection }) still validates the source with the core collection class.
In dev mode, TanStack DB also throws DuplicateDbInstanceError if two instances are detected.
Diagnose:
If multiple versions appear, fix with one of:
pnpm overrides (in root package.json):
Vite resolve.alias (in vite.config.ts):
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 93 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingpackages/react-db/skills/react-db/SKILL.md
Popularity
- Repository stars
- 3,880
- Repository forks
- 258
- 7-day trend score
- 41
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/tanstack/db/react-db)