AGENT SKILL
tanstack
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-06-24
- Stars
- ★ 67
- Forks
- 24
02 资源文件 18
- 其他customize.toml1.6 KB
- 资产文件data/domain-complexity.csv7.2 KB
- 参考文档data/prd-purpose.md7.1 KB
- 资产文件data/project-types.csv3.1 KB
- 参考文档steps-v/step-v-01-discovery.md7.3 KB
- 参考文档steps-v/step-v-02-format-detection.md6.5 KB
- 参考文档steps-v/step-v-02b-parity-check.md6.4 KB
- 参考文档steps-v/step-v-03-density-validation.md5.8 KB
- 参考文档steps-v/step-v-04-brief-coverage-validation.md7.2 KB
- 参考文档steps-v/step-v-05-measurability-validation.md7.1 KB
- 参考文档steps-v/step-v-06-traceability-validation.md7.2 KB
- 参考文档steps-v/step-v-07-implementation-leakage-validation.md7.0 KB
- 参考文档steps-v/step-v-08-domain-compliance-validation.md7.7 KB
- 参考文档steps-v/step-v-09-project-type-validation.md8.6 KB
- 参考文档steps-v/step-v-10-smart-validation.md6.7 KB
- 参考文档steps-v/step-v-11-holistic-quality-validation.md8.7 KB
- 参考文档steps-v/step-v-12-completeness-validation.md8.2 KB
- 参考文档steps-v/step-v-13-report-complete.md8.2 KB
03 SKILL.md 正文
TanStack
Overview
The TanStack ecosystem provides type-safe client libraries for React: Query for declarative data fetching and caching, Router for fully typed routing with search parameters, Table for headless data tables with sorting/filtering/pagination, and Virtual for rendering large lists efficiently.
Instructions
- When fetching data, use
useQuery()with hierarchical query keys (e.g.,["users", userId, "posts"]) and configurestaleTimebased on freshness needs (0 for real-time, 5 minutes for dashboards, Infinity for static data). - When performing mutations, use
useMutation()withonSuccessfor cache invalidation viaqueryClient.invalidateQueries(), andonMutatefor optimistic updates with rollback. - When building tables, use TanStack Table's headless approach with typed column definitions, and combine with
@tanstack/react-virtualfor datasets with 10,000+ rows. - When routing, use TanStack Router for fully typed route parameters and search params with Zod validation, file-based routes with automatic type generation, and route-level data loading.
- When handling pagination, use
useInfiniteQuery()for infinite scroll or cursor-based patterns, and server-side pagination in TanStack Table. - When prefetching, use
queryClient.prefetchQuery()for anticipated navigation anduseSuspenseQuery()for React Suspense integration. - When virtualizing lists, use
@tanstack/react-virtualwithestimateSizefor scroll position prediction and support for dynamic, variable-height items.
Examples
Example 1: Build a data dashboard with Query and Table
User request: "Create a dashboard with server-paginated data table and real-time stats"
Actions:
- Set up TanStack Query with appropriate
staleTimeand refetch intervals for stats - Define TanStack Table with typed columns, server-side sorting and pagination
- Implement filter controls with column filters and global search
- Add optimistic updates for inline row editing with mutation rollback
Output: A dashboard with efficient data fetching, server-managed table pagination, and instant edit feedback.
Example 2: Add type-safe routing with data prefetching
User request: "Set up TanStack Router with typed search parameters and data preloading"
Actions:
- Define routes with typed parameters and Zod-validated search params
- Add route loaders for data fetching with built-in caching
- Configure
<Link>components with type-checked params and search params - Enable prefetching on hover for instant navigation
Output: A fully typed routing layer where invalid params cause TypeScript errors at compile time.
Guidelines
- Use query key factories for consistent cache keys:
const userKeys = { all: ["users"], detail: (id) => ["users", id] }. - Set
staleTimebased on data freshness needs: 0 for real-time, 5 minutes for dashboards, Infinity for static data. - Always define
onErrorfor mutations; silent failures confuse users. - Use
placeholderDatainstead ofinitialDatafor loading states; placeholder does not write to cache. - Use TanStack Table with
@tanstack/react-virtualfor large datasets; do not render thousands of DOM nodes. - Keep query functions pure: they receive
queryKeyand return data with no side effects. - Use
queryClient.invalidateQueries()after mutations instead of manual cache updates for simplicity.