tanstack-query-expert
Что он делает
Этот эксперт помогает разработчикам управлять данными в веб-приложениях на React и Next.js. Он организует загрузку, обновление и отображение данных, делая приложение быстрее и стабильнее.
Когда использовать
- ✓Когда вы начинаете загружать данные в приложении на React или Next.js.
- ✓Когда хотите, чтобы интерфейс работал быстрее, обновляя данные без полной перезагрузки страницы.
- ✓Когда нужно связать загрузку данных с Next.js для слаженной работы на сервере и в браузере.
Ссылка на скилл
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/tanstack-query-expert/SKILL.mdСкопируйте и вставьте её в ваш ИИ (Claude, ChatGPT или Cursor) с просьбой следовать инструкциям.
Как использовать
Самый простой способ: скопируйте сообщение и вставьте его в свой ИИ. Он прочитает скилл и выполнит инструкции.
Готовое сообщение для вставки
Для Claude Code, Codex или Cursor: запустите в папке проекта, и скилл установится.
Скачайте SKILL.md и положите его в папку скиллов вашего агента.
Пример запроса к вашему ИИ
“Как настроить TanStack Query, чтобы загружать данные пользователей и выводить их на экран?”
5 новых скиллов в неделю. 1 минута чтения.
Как это работает
Эксперт объясняет, как использовать паттерн под названием «кастомный хук», чтобы организовать загрузку данных. Это включает описание того, как получать данные, как их идентифицировать и как обрабатывать обновления и ошибки.
Технический текст (оригинальный SKILL.md)
Оригинальный текст автора на английском, прямо с GitHub.
TanStack Query Expert
You are a production-grade TanStack Query (formerly React Query) expert. You help developers build robust, performant asynchronous state management layers in React and Next.js applications. You master declarative data fetching, cache invalidation, optimistic UI updates, background syncing, error boundaries, and server-side rendering (SSR) hydration patterns.
When to Use This Skill
- Use when setting up or refactoring data fetching logic (replacing
useEffect+useState) - Use when designing query keys (Array-based, strictly typed keys)
- Use when configuring global or query-specific
staleTime,gcTime, andretrybehavior - Use when writing
useMutationhooks for POST/PUT/DELETE requests - Use when invalidating the cache (
queryClient.invalidateQueries) after a mutation - Use when implementing Optimistic Updates for instant UX feedback
- Use when integrating TanStack Query with Next.js App Router (Server Components + Client Boundary hydration)
Core Concepts
Why TanStack Query?
TanStack Query is not just for fetching data; it's an asynchronous state manager. It handles caching, background updates, deduplication of multiple requests for the same data, pagination, and out-of-the-box loading/error states.
Rule of Thumb: Never use useEffect to fetch data if TanStack Query is available in the stack.
Query Definition Patterns
The Custom Hook Pattern (Best Practice)
Always abstract useQuery calls into custom hooks to encapsulate the fetching logic, TypeScript types, and query keys.
import { useQuery } from '@tanstack/react-query';
// 1. Define strict types
type User = { id: string; name: string; status: 'active' | 'inactive' };
// 2. Define the fetcher function
const fetchUser = async (userId: string): Promise<User> => {
const res = await fetch(`/api/users/${userId}`);
if (!res.ok) throw new Error('Failed to fetch user');
return res.json();
};
// 3. Export a custom hook
export const useUser = (userId: string) => {
return useQuery({
queryKey: ['users', userId], // Array-based query key
queryFn: () => fetchUser(userId),
staleTime: 1000 * 60 * 5, // Data is fresh for 5 minutes (no background refetching)
enabled: !!userId, // Dependent query: only run if userId exists
});
};
Advanced Query Keys
Query keys uniquely identify the cache. They must be arrays, and order matters.
// Filtering / Sorting
useQuery({
queryKey: ['issues', { status: 'open', sort: 'desc' }],
queryFn: () => fetchIssues({ status: 'open', sort: 'desc' })
});
// Factory pattern for query keys (Highly recommended for large apps)
export const issueKeys = {
all: ['issues'] as const,
lists: () => [...issueKeys.all, 'list'] as const,
list: (filters: string) => [...issueKeys.lists(), { filters }] as const,
details: () => [...issueKeys.all, 'detail'] as const,
detail: (id: number) => [...issueKeys.details(), id] as const,
};
Mutations & Cache Invalidation
Basic Mutation with Invalidation
When you modify data on the server, you must tell the client cache that the old data is now stale.
import { useMutation, useQueryClient } from '@tanstack/react-query';
export const useCreatePost = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async (newPost: { title: string }) => {
const res = await fetch('/api/posts', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(newPost),
});
return res.json();
},
// On success, invalidate the 'posts' cache to trigger a background refetch
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['posts'] });
},
});
};
Optimistic Updates
Give the user instant feedback by updating the cache before the server responds, and rolling back if the request fails.
export const useUpdateTodo = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: updateTodoFn,
// 1. Triggered immediately when mutate() is called
onMutate: async (newTodo) => {
// Cancel any outgoing refetches so they don't overwrite our optimistic update
await queryClient.cancelQueries({ queryKey: ['todos'] });
// Snapshot the previous value
const previousTodos = queryClient.getQueryData(['todos']);
// Optimistically update to the new value
…
Частые вопросы
Что такое TanStack Query?
Это инструмент для управления данными, которые меняются со временем, в веб-приложениях. Он занимается загрузкой, кешированием и автоматическим обновлением данных.
Почему не использовать `useEffect` для загрузки данных?
TanStack Query эффективнее. Он управляет кешем, не отправляет повторные одинаковые запросы и сам обрабатывает состояния загрузки и ошибок, чего `useEffect` сам по себе не умеет.
Что такое «query keys»?
Это уникальные идентификаторы для каждого набора загружаемых данных. По ним TanStack Query понимает, какие данные загружать, обновлять или помечать как устаревшие.
Подробности
Оригинальное описание автора
Expert in TanStack Query (React Query) — asynchronous state management. Covers data fetching, stale time configuration, mutations, optimistic updates, and Next.js App Router (SSR) integration.
Популярность
- Звёзды на GitHub
- 48k
- Место в рейтинге
- #5927
- Лицензия
- MIT
- Обновлён
- 15.10.2026
Комментарии
- …
Другие скиллы из этого репозитория
00-andruia-consultant
48kПомогает агенту начинать или улучшать ИИ-проекты: анализирует код, подбирает инструменты и составляет план на испанском.
007
48kАгент проводит аудит безопасности и моделирование угроз для защиты проектов.
10-andruia-skill-smith
48kПомогает агенту создавать и улучшать ИИ-инструменты: описание работы, документация и проверка структуры.
20-andruia-niche-intelligence
48kАгент составляет обзор отрасли: контекст, правила, паттерны использования и риски по надёжным источникам.
Похожие скиллы
angular-developer
280kПомогает агенту писать код на Angular и советовать по структуре проекта. Полезен для новых проектов, создания частей кода и улучшения производительности.
frontend-a11y
280kПомогает агенту делать веб-интерфейсы доступными для всех, чтобы сайты и приложения работали с программами чтения с экрана и клавиатурой.
frontend-patterns
280kАгент применяет современные паттерны фронтенд-разработки: оптимизирует производительность, управляет состоянием и следует практикам React и Next.js.