Tanstack query
Skill Pythoughts-labs/react-frontend-skills/skills/tanstack-query
TanStack Query v5 performance optimization for data fetching, caching, mutations, and query patterns. This skill should be used when using useQuery, useMutation, queryClient, prefetch patterns, or TanStack Query caching. This skill does NOT cover generating query hooks from OpenAPI (use orval skill) or mocking API responses in tests (use test-msw skill).From its SKILL.md
npx -y skills add Pythoughts-labs/react-frontend-skills --skill tanstack-queryAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its file declares
Copied from the file, not written here
The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
5.1 KB, ~1.1k tokens by cl100k_base, as published. Nobody here has run it
TanStack Query Best Practices
Comprehensive performance optimization guide for TanStack Query v5 applications. Contains 40 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Writing new queries, mutations, or data fetching logic
- Implementing caching strategies (staleTime, gcTime)
- Reviewing code for performance issues or request waterfalls
- Refactoring existing TanStack Query code
- Implementing infinite queries, Suspense, or optimistic updates
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Query Key Structure | CRITICAL | tquery- |
| 2 | Caching Configuration | CRITICAL | cache- |
| 3 | Mutation Patterns | HIGH | mutation- |
| 4 | Prefetching & Waterfalls | HIGH | prefetch- |
| 5 | Infinite Queries | MEDIUM | infinite- |
| 6 | Suspense Integration | MEDIUM | suspense- |
| 7 | Error & Retry Handling | MEDIUM | error- |
| 8 | Render Optimization | LOW-MEDIUM | render- |
Quick Reference
1. Query Key Structure (CRITICAL)
tquery-key-factories- Use centralized query key factoriestquery-hierarchical-keys- Structure keys from generic to specifictquery-always-arrays- Always use array query keystquery-serializable-objects- Use serializable objects in keystquery-options-pattern- Use queryOptions for type-safe sharingtquery-colocate-keys- Colocate query keys with features
2. Caching Configuration (CRITICAL)
cache-staletime-gctime- Understand staleTime vs gcTimecache-global-defaults- Configure global defaults appropriatelycache-placeholder-vs-initial- Use placeholderData vs initialData correctlycache-invalidation-precision- Invalidate with precisioncache-refetch-triggers- Control automatic refetch triggerscache-enabled-option- Use enabled for conditional queries
3. Mutation Patterns (HIGH)
mutation-optimistic-updates- Implement optimistic updates with rollbackmutation-invalidate-onsettled- Invalidate in onSettled, not onSuccessmutation-cancel-queries- Cancel queries before optimistic updatesmutation-setquerydata- Use setQueryData for immediate cache updatesmutation-avoid-parallel- Avoid parallel mutations on same data
4. Prefetching & Waterfalls (HIGH)
prefetch-avoid-waterfalls- Avoid request waterfallsprefetch-on-hover- Prefetch on hover for perceived speedprefetch-in-queryfn- Prefetch dependent data in queryFnprefetch-server-components- Prefetch in Server Componentsprefetch-flatten-api- Flatten API to reduce waterfalls
5. Infinite Queries (MEDIUM)
infinite-max-pages- Limit infinite query pages with maxPagesinfinite-flatten-pages- Flatten pages for renderinginfinite-refetch-behavior- Understand infinite query refetch behaviorinfinite-loading-states- Handle infinite query loading states correctly
6. Suspense Integration (MEDIUM)
suspense-use-suspense-hooks- Use Suspense hooks for simpler loading statessuspense-error-boundaries- Always pair Suspense with Error Boundariessuspense-parallel-queries- Combine Suspense queries with useSuspenseQueriessuspense-boundaries-placement- Place Suspense boundaries strategically
7. Error & Retry Handling (MEDIUM)
error-retry-config- Configure retry with exponential backofferror-conditional-retry- Use conditional retry based on error typeerror-global-handler- Use global error handler for common errorserror-display-patterns- Display errors appropriatelyerror-throw-on-error- Use throwOnError with Error Boundaries
8. Render Optimization (LOW-MEDIUM)
render-select-memoize- Memoize select functionsrender-select-derived- Use select to derive data and reduce re-rendersrender-notify-props- Use notifyOnChangeProps to limit re-rendersrender-structural-sharing- Understand structural sharingrender-tracked-props- Avoid destructuring all properties
How to Use
Read individual reference files for detailed explanations and code examples:
- Reference files:
references/{prefix}-{slug}.md
Each reference file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Additional context and references
Related Skills
- For generating type-safe query hooks, see
orvalskill - For mocking API responses in tests, see
test-mswskill - For React 19 data fetching patterns, see
react-19skill
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md
What ships with it: 41 files
89.5 KB alongside SKILL.md
references/
- cache-enabled-option.md2.0 KB
- cache-global-defaults.md2.0 KB
- cache-invalidation-precision.md2.1 KB
- cache-placeholder-vs-initial.md2.1 KB
- cache-refetch-triggers.md2.0 KB
- cache-staletime-gctime.md2.2 KB
- error-conditional-retry.md2.1 KB
- error-display-patterns.md2.2 KB
- error-global-handler.md2.2 KB
- error-retry-config.md1.8 KB
- error-throw-on-error.md2.1 KB
- infinite-flatten-pages.md2.6 KB
- infinite-loading-states.md2.4 KB
- infinite-max-pages.md2.2 KB
- infinite-refetch-behavior.md2.0 KB
- mutation-avoid-parallel.md2.0 KB
- mutation-cancel-queries.md2.0 KB
- mutation-invalidate-onsettled.md1.9 KB
- mutation-optimistic-updates.md2.3 KB
- mutation-setquerydata.md1.9 KB
- prefetch-avoid-waterfalls.md2.5 KB
- prefetch-flatten-api.md2.0 KB
- prefetch-in-queryfn.md1.9 KB
- prefetch-on-hover.md2.0 KB
- prefetch-server-components.md2.2 KB
- render-notify-props.md2.1 KB
- render-select-derived.md2.3 KB
- render-select-memoize.md2.0 KB
- render-structural-sharing.md2.2 KB
- render-tracked-props.md1.9 KB
- suspense-boundaries-placement.md2.2 KB
- suspense-error-boundaries.md2.2 KB
- suspense-parallel-queries.md2.0 KB
- suspense-use-suspense-hooks.md2.0 KB
- tquery-always-arrays.md1.4 KB
- tquery-colocate-keys.md1.8 KB
- tquery-hierarchical-keys.md1.9 KB
- tquery-key-factories.md1.7 KB
- tquery-options-pattern.md2.0 KB
- AGENTS.md7.4 KB
1 more file not listed here. See all 41 in the repository.