pitfalls-tanstack-query
БесплатноБез исполняемых скриптовНе проверенTanStack Query v5 patterns and common pitfalls. Use when implementing data fetching, cache invalidation, or debugging stale data issues. Triggers on…
Об этом скилле
TanStack Query v5 Pitfalls
Common pitfalls and correct patterns for TanStack Query v5.
When to Use
- Implementing data fetching with useQuery
- Setting up mutations with useMutation
- Debugging stale data or cache issues
- Reviewing code that uses TanStack Query
- Migrating from v4 to v5
Workflow
Step 1: Check Query Keys
Verify query keys use full URL paths for proper deduplication.
Step 2: Verify Invalidation
Ensure mutations invalidate relevant queries on success.
Step 3: Check v5 Patterns
Verify v5-specific patterns (isPending vs isLoading).
Correct Usage
// ✅ CORRECT: Full URL path in queryKey
const { data } = useQuery({
queryKey: ['/api/strategies', strategyId],
queryFn: () => api.get(`/api/strategies/${strategyId}`),
});
// ✅ CORRECT: Invalidate after mutation
const mutation = useMutation({
mutationFn: (data) => api.post('/api/strategies', data),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['strategies'] });
},
});
// ✅ CORRECT: Type responses with schema types
import type { Strategy } from '@shared/schema';
const { data } = useQuery<{ data: Strategy[] }>(...);
Anti-Patterns
// ❌ WRONG: Short queryKey
queryKey: ['strategy'] // Won't dedupe properly
// ❌ WRONG: Forgetting to invalidate
onSuccess: () => { navigate('/'); } // Stale cache!
// ❌ WRONG: Using isLoading for mutations
mutation.isLoading // Use isPending in v5
Optimistic Updates
// ✅ Update UI immediately, rollback on error
const mutation = useMutation({
mutationFn: updateStrategy,
onMutate: async (newData) => {
await queryClient.cancelQueries({ queryKey: ['strategy', id] });
const previous = queryClient.getQueryData(['strategy', id]);
// Optimistic update
queryClient.setQueryData(['strategy', id], newData);
return { previous };
},
onError: (err, newData, context) => {
// Rollback on error
queryClient.setQueryData(['strategy', id], context.previous);
toast.error('Update failed');
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ['strategy', id] });
},
});
Quick Checklist
- QueryKeys use full URL paths
- Mutations invalidate relevant queries
- Using isPending (not isLoading) for mutations in v5
- Responses typed with schema types
Установить pitfalls-tanstack-query в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл pitfalls-tanstack-query?
TanStack Query v5 patterns and common pitfalls. Use when implementing data fetching, cache invalidation, or debugging stale data issues. Triggers on: useQuery, useMutation, queryKey, invalidate, TanStack, React Query.
Как установить скилл pitfalls-tanstack-query?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл pitfalls-tanstack-query запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic