Provides TanStack Query v5 best practices for data fetching, caching, mutations, and server state management in React. Covers setup, optimistic updates, SSR integration, and v4→v5 migration.
Ships in frontend. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Version: @tanstack/react-[email protected] Requires: React 18.0+, TypeScript 4.7+
variables from pending mutations, no cache manipulation neededuseErrorBoundaryonline | always | offlineFirst)queryOptions)onError/onSuccess/onSettled now receive 4 params (added onMutateResult)npm install @tanstack/react-query@latest @tanstack/react-query-devtools@latest
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 1000 * 60 * 5, // 5 min
gcTime: 1000 * 60 * 60, // 1 hour
refetchOnWindowFocus: false,
},
},
})
function App() {
return (
<QueryClientProvider client={queryClient}>
<YourApp />
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
)
}
If using Query + Router (or other TanStack libraries), use the unified TanStackDevtools shell instead of individual devtools components:
npm install -D @tanstack/react-devtools
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools'
import { TanStackDevtools } from '@tanstack/react-devtools'
function App() {
return (
<QueryClientProvider client={queryClient}>
<YourApp />
<TanStackDevtools
config={{ position: 'bottom-right' }}
plugins={[
{ name: 'TanStack Query', render: <ReactQueryDevtoolsPanel /> },
// Add more plugins: Router, etc.
]}
/>
</QueryClientProvider>
)
}
Use *Panel variants (ReactQueryDevtoolsPanel, TanStackRouterDevtoolsPanel) when embedding inside TanStackDevtools.
import { useQuery, useMutation, useQueryClient, queryOptions } from '@tanstack/react-query'
const todosQueryOptions = queryOptions({
queryKey: ['todos'],
queryFn: async () => {
const res = await fetch('/api/todos')
if (!res.ok) throw new Error('Failed to fetch')
return res.json()
},
})
function useTodos() {
return useQuery(todosQueryOptions)
}
function useAddTodo() {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async (newTodo: { title: string }) => {
const res = await fetch('/api/todos', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(newTodo),
})
if (!res.ok) throw new Error('Failed to add')
return res.json()
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['todos'] })
},
})
}
| Priority | Category | Rule File | Impact |
|---|---|---|---|
| CRITICAL | Query Keys | rules/qk-query-keys.md | Prevents cache bugs and data inconsistencies |
| CRITICAL | Caching | rules/cache-configuration.md | Optimizes performance and data freshness |
| HIGH | Invalidation | rules/cache-invalidation.md | Ensures stale data is properly refreshed |
| HIGH | Mutations | rules/mut-basics.md | Ensures data integrity after writes |
| HIGH | Optimistic Updates | rules/mut-optimistic-updates.md | Responsive UI during mutations |
| HIGH | Error Handling | rules/err-error-handling.md | Prevents poor user experiences |
| MEDIUM | Prefetching | rules/pf-prefetching.md | Improves perceived performance |
| MEDIUM | Infinite Queries | rules/inf-infinite-queries.md | Prevents pagination bugs |
| MEDIUM | SSR/Hydration | rules/ssr-hydration.md | Enables proper server rendering |
| MEDIUM | Parallel Queries | rules/parallel-queries.md | Dynamic parallel fetching |
| LOW | Performance | rules/perf-optimization.md | Reduces unnecessary re-renders |
| LOW | Offline Support | rules/offline-support.md | Enables offline-first patterns |
useQuery({ queryKey, queryFn, ...options })['todos'], ['todos', id], ['todos', { filter }]if (!res.ok) throw new Error('Failed')if (isPending) return <Loading />onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] })useQuery, useSuspenseQuery, prefetchQueryuseQuery(['todos'], fetchTodos) — removed in v5onSuccess/onError/onSettled removed from queries (still work in mutations) — use useEffect insteadisPendingplaceholderData: keepPreviousData| v4 | v5 | Notes |
|---|---|---|
useQuery(['key'], fn, opts) | useQuery({ queryKey, queryFn, ...opts }) | Object syntax only |
cacheTime | gcTime | Renamed |
isLoading (no data) | isPending | isLoading = isPending && isFetching |
keepPreviousData: true | placeholderData: keepPreviousData | Import keepPreviousData helper |
useErrorBoundary | throwOnError | Renamed |
onSuccess/onError/onSettled on queries | Removed | Use useEffect for side effects |
pageParam = 0 default | initialPageParam: 0 | Required for infinite queries |
status: 'loading' | status: 'pending' | Renamed |
onError(err, vars, ctx) | onError(err, vars, onMutateResult, ctx) | v5.89+ added 4th param |
void prefetchQuery + useSuspenseQuery with conditional isFetching render causes hydration errors. Workaround: await prefetch or don't render based on fetchStatususeQuery + server prefetch can mismatch isLoading between server/client. Use useSuspenseQuery insteadretryOnMount: false in addition to refetchOnMount: falsemutation.state.variables typed as unknown due to fuzzy matching. Cast explicitly in select callbackrefetchType: 'all' to include inactive queries// Dependent queries (B waits for A)
const { data: user } = useQuery({ queryKey: ['user', id], queryFn: () => fetchUser(id) })
const { data: posts } = useQuery({
queryKey: ['posts', user?.id],
queryFn: () => fetchPosts(user!.id),
enabled: !!user,
})
// Parallel queries
const results = useQueries({
queries: ids.map(id => ({ queryKey: ['item', id], queryFn: () => fetchItem(id) })),
combine: (results) => ({ data: results.map(r => r.data), pending: results.some(r => r.isPending) }),
})
// Prefetch on hover
const handleHover = () => queryClient.prefetchQuery({ queryKey: ['item', id], queryFn: () => fetchItem(id) })
// Infinite scroll
useInfiniteQuery({
queryKey: ['posts'],
queryFn: ({ pageParam }) => fetchPosts(pageParam),
initialPageParam: 0,
getNextPageParam: (lastPage) => lastPage.nextCursor,
})
// Query cancellation
queryFn: async ({ signal }) => {
const res = await fetch(`/api/search?q=${query}`, { signal })
return res.json()
}
// Data transformation
useQuery({ queryKey: ['todos'], queryFn: fetchTodos, select: (data) => data.filter(t => t.completed) })
agents/openai.yaml (opens in a new tab)rules/cache-configuration.md (opens in a new tab)rules/cache-invalidation.md (opens in a new tab)rules/err-error-handling.md (opens in a new tab)rules/inf-infinite-queries.md (opens in a new tab)rules/mut-basics.md (opens in a new tab)rules/mut-optimistic-updates.md (opens in a new tab)rules/offline-support.md (opens in a new tab)rules/parallel-queries.md (opens in a new tab)rules/perf-optimization.md (opens in a new tab)rules/pf-prefetching.md (opens in a new tab)rules/qk-query-keys.md (opens in a new tab)rules/ssr-hydration.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
tanstack-query, react-query, data-fetching, caching, mutations, server-state
/frontend:tanstack-queryfrom frontend
npx claudepluginhub fellipeutaka/leon --plugin frontend34 skills in this plugin
/ai-sdkAnswer questions about the AI SDK and help build AI-powered features. Use when developers: (1) Ask about AI SDK functions like generateText, streamText, ToolLoopAgent, embed, or tools, (2) Want to build AI agents, chatbots, RAG systems, or text generation features, (3) Have questions about AI providers (OpenAI, Anthropic, Google, etc.), streaming, tool calling, structured output, or embeddings, (4) Use React hooks like useChat or useCompletion. Triggers on: "AI SDK", "Vercel AI SDK", "generateText", "streamText", "add AI to my app", "build an agent", "tool calling", "structured output", "useChat"./baseline-uiQuickly deslop UI code by fixing spacing, hierarchy, typography, and small layout issues. Use when the interface needs a fast cleanup or polish pass./Other plugins' skills for the same job