tanstack-query
TanStack Query v5 data fetching and caching.
- License 许可
- MIT
- 最近更新
- 2026-11-06
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- tanstack-query
- license
- MIT
- metadata
- { "author": "community", "version": "1.0.0" }
- description
- TanStack Query v5 data fetching and caching.
02 资源文件 41
- 参考文档references/cache-enabled-option.md2.5 KB
- 参考文档references/cache-global-defaults.md2.0 KB
- 参考文档references/cache-invalidation-precision.md2.1 KB
- 参考文档references/cache-placeholder-vs-initial.md2.1 KB
- 参考文档references/cache-refetch-triggers.md2.0 KB
- 参考文档references/cache-staletime-gctime.md2.2 KB
- 参考文档references/error-conditional-retry.md2.1 KB
- 参考文档references/error-display-patterns.md2.2 KB
- 参考文档references/error-global-handler.md2.2 KB
- 参考文档references/error-retry-config.md1.8 KB
- 参考文档references/error-throw-on-error.md2.1 KB
- 参考文档references/infinite-flatten-pages.md2.6 KB
- 参考文档references/infinite-loading-states.md2.4 KB
- 参考文档references/infinite-max-pages.md2.2 KB
- 参考文档references/infinite-refetch-behavior.md2.0 KB
- 参考文档references/mutation-avoid-parallel.md2.5 KB
- 参考文档references/mutation-cancel-queries.md2.0 KB
- 参考文档references/mutation-invalidate-onsettled.md2.5 KB
- 参考文档references/mutation-optimistic-updates.md2.3 KB
- 参考文档references/mutation-setquerydata.md1.9 KB
- 参考文档references/prefetch-avoid-waterfalls.md2.5 KB
- 参考文档references/prefetch-flatten-api.md2.1 KB
- 参考文档references/prefetch-in-queryfn.md2.9 KB
- 参考文档references/prefetch-infinite-query.md2.7 KB
- 参考文档references/prefetch-on-hover.md2.4 KB
- 参考文档references/prefetch-server-components.md2.3 KB
- 参考文档references/render-notify-props.md2.0 KB
- 参考文档references/render-select-derived.md2.3 KB
- 参考文档references/render-select-memoize.md2.0 KB
- 参考文档references/render-structural-sharing.md2.2 KB
- 参考文档references/render-tracked-props.md1.9 KB
- 参考文档references/suspense-boundaries-placement.md2.2 KB
- 参考文档references/suspense-error-boundaries.md2.2 KB
- 参考文档references/suspense-parallel-queries.md2.0 KB
- 参考文档references/suspense-use-suspense-hooks.md2.0 KB
- 参考文档references/tquery-always-arrays.md1.4 KB
- 参考文档references/tquery-colocate-keys.md1.8 KB
- 参考文档references/tquery-hierarchical-keys.md1.9 KB
- 参考文档references/tquery-key-factories.md1.7 KB
- 参考文档references/tquery-options-pattern.md2.2 KB
- 参考文档references/tquery-serializable-objects.md1.8 KB
03 SKILL.md 正文
TanStack Query Best Practices
Comprehensive performance optimization guide for TanStack Query v5 applications. Contains 41 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 or skipToken for conditional queries
3. Mutation Patterns (HIGH)
mutation-optimistic-updates- Implement optimistic updates with rollbackmutation-invalidate-onsettled- Choose invalidation callbacks by mutation contractmutation-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- Start follow-up prefetches when keys become knownprefetch-server-components- Prefetch in Server Componentsprefetch-infinite-query- Prefetch infinite lists with queryClient.infiniteQuery (5.102+)prefetch-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- Rely on tracked properties before notifyOnChangePropsrender-structural-sharing- Understand structural sharingrender-tracked-props- Preserve tracked-property optimization
How to Use
Run in the project root first:
npx -y @pymodel/react-frontend-skills detect # installed vs. targeted versions
npx -y @pymodel/react-frontend-skills scan --skill tanstack-query # deprecated APIs → rule IDs
Read references/<rule-id>.md for each rule above that matches the task and for each scan hit: why it matters, then incorrect vs. correct code.
Related Skills
- For mocking API responses in tests, see
mswskill - For React 19 data fetching patterns, see
reactskill
04 同仓库更多 Skills
frontend-slides
Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.
design-dna
Extract, define, and apply design DNA across three dimensions: design system (tokens), design style (qualitative feel), and visual effects (Canvas, WebGL, 3D, particles, shaders, scroll effects, etc.). Use this skill when: (1) a user wants to see the full 3-dimension design structure/schema, (2) a user provides images, screenshots, or URLs of reference designs and wants them analyzed into a structured JSON profile covering all three dimensions, (3) a user has a Design DNA JSON and content and wants a design generated from it, or (4) any combination of these phases. Triggers on "design DNA", "extract design style", "analyze design", "design tokens from reference", "generate design from JSON", "design system from screenshot", "design profile", "style guide JSON", "visual effects analysis", "design with effects", "3d design analysis".
wireframe
Generate JSON wireframe with HTML preview
social-publishing
Schedule and publish social media posts across 13 platforms (X, LinkedIn, Instagram, Facebook Pages, TikTok, Discord, Telegram, YouTube, Reddit, WordPress, Pinterest) via the SocialClaw API. Use when the user wants to publish, schedule, or manage social media content programmatically. Requires SOCIALCLAW_API_KEY.
hermes-tweet
Install and operate Hermes Tweet, a Hermes Agent plugin for X/Twitter research, timeline reading, tweet analysis, and approval-gated private or state-changing operations. Use this skill when installing Hermes Tweet, researching X/Twitter accounts, monitoring launch signals, investigating mentions, auditing giveaways, or preparing gated X operations. Use proactively when a Hermes Agent workflow needs current X/Twitter context. Requires XQUIK_API_KEY for read and action tools.
refactoring-ui
Audit and fix visual hierarchy, spacing, color, and depth in web UIs. Use when the user mentions "my UI looks off" (or amateur/unprofessional), "fix the design", "Tailwind styling", "color palette", "visual hierarchy", "design system", "spacing scale", or "component styling". Also trigger when building consistent design tokens, creating dark mode themes, improving data-visualization clarity, or polishing UI details before launch. Covers grayscale-first workflow, constrained design scales, shadows, and component styling. For typeface selection, see web-typography. For usability audits, see ux-heuristics.