Nextjs tanstack query
Skill fusengine/agents/plugins/nextjs-expert/skills/nextjs-tanstack-query
TanStack Query v5 integration with Next.js 16. Server-side prefetching, hydration, useQuery, useMutation, cache management. Use when: implementing client-side data fetching with caching, server-side prefetching with hydration, or optimistic mutations in Next.js.From its SKILL.md
npx -y skills add fusengine/agents --skill nextjs-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
- 22 stars22 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.
SKILL.md
2.9 KB, 591 tokens by cl100k_base, as published. Nobody here has run it
TanStack Query for Next.js
TanStack Query v5 provides powerful server state management with Next.js 16 integration.
Agent Workflow (MANDATORY)
Before ANY implementation, use TeamCreate to spawn 3 agents:
- fuse-ai-pilot:explore-codebase - Analyze existing data fetching patterns
- fuse-ai-pilot:research-expert - Verify latest TanStack Query v5 docs
- mcp__context7__query-docs - Check TanStack Query + Next.js patterns
After implementation, run fuse-ai-pilot:sniper for validation.
Overview
When to Use
- Client-side data fetching with caching and revalidation
- Server-side prefetching with hydration to client
- Optimistic updates for mutations
- Infinite scrolling and pagination
- Real-time data synchronization
Why TanStack Query
| Feature | Benefit |
|---|---|
| Server prefetching | Data ready on first render, no loading flash |
| Automatic caching | Deduplication, stale-while-revalidate |
| Mutations | Optimistic updates, rollback on error |
| DevTools | Visual cache inspection |
| TypeScript-first | Full type inference |
Critical Rules
- One QueryClient per request - Create in Server Component, share via context
- Prefetch in Server Components - Use
prefetchQueryfor SSR data - HydrationBoundary required - Wrap client tree to transfer server cache
- Query keys must be serializable - Arrays of strings/numbers only
staleTimeon prefetched queries - Prevent immediate refetch on mount- Never use
queryClientin Client Components directly - Use hooks
Installation
bun add @tanstack/react-query @tanstack/react-query-devtools
Best Practices
- Prefetch on server - Avoid loading states for critical data
- Set
staleTime- Prevent unnecessary refetches after hydration - Collocate query keys - Define keys near their usage
- Invalidate on mutation - Use
invalidateQueriesafter writes - Error boundaries - Use
throwOnErrorfor critical queries - DevTools in dev only - Wrap in
process.env.NODE_ENVcheck
Reference Guide
| Need | Reference |
|---|---|
| useQuery, useMutation | query-patterns.md |
| Server prefetching | hydration.md |
| QueryClient setup | hydration.md |
| Cache invalidation | query-patterns.md |
What ships with it: 2 files
5.2 KB alongside SKILL.md
references/
- hydration.md2.6 KB
- query-patterns.md2.6 KB