state-management
React Query and Zustand patterns for state management. Use when implementing data fetching, caching, mutations, or client-side state. Triggers on tasks…

Установить state-management в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
State Management with React Query + Zustand
Version 1.2.0 | TanStack Query v5 | Zustand v5 | React 19.x | TypeScript 5.x–7.x | November 2026
Note: This document provides comprehensive patterns for AI agents and LLMs working with TanStack Query v5 and Zustand v5. All examples are verified against v5 APIs. Optimized for automated refactoring, code generation, and state management best practices.
v5 Breaking Changes (Quick Reference)
TanStack Query v5:
cacheTime→gcTimekeepPreviousDataoption →placeholderData: keepPreviousData(imported helper)isPreviousData→isPlaceholderDataonSuccess/onError/onSettledremoved fromuseQuery— still valid onuseMutationsuspense: trueonuseQueryremoved → useuseSuspenseQueryuseErrorBoundary→throwOnError
Zustand v5:
shallowas 2nd arg removed →useShallowfromzustand/shallow- Selectors returning new references need
useShallowto avoid infinite loops
Security: Persist Middleware
Never persist auth tokens, passwords, or secrets to localStorage/sessionStorage. Use
partializeto persist only non-sensitive state. Manage tokens via HttpOnly cookies.
Comprehensive patterns for server state (React Query) and client state (Zustand). Contains 27 rules for efficient data fetching and state management. Targets React 19.x (both libraries also support React 18), TypeScript 5.x–7.x, TanStack Query v5 and Zustand v5.
When to Apply
Reference these guidelines when:
- Fetching data from APIs
- Managing server state and caching
- Handling mutations and optimistic updates
- Creating client-side stores
- Combining React Query with Zustand
Rule Categories by Priority
| Priority | Category | Impact | Rules |
|---|---|---|---|
| 1 | Query Fundamentals | CRITICAL | 6 |
| 2 | Mutation & Updates | CRITICAL | 5 |
| 3 | Zustand Stores | CRITICAL | 2 |
| 4 | Advanced Queries | HIGH | 6 |
| 5 | Cache & Performance | HIGH-MEDIUM | 8 |
TanStack Query rules use the rq- prefix and Zustand rules use zs-. 27 rules in total.
Quick Reference
1. Query Fundamentals (CRITICAL)
rq-usequery- useQuery hook patternsrq-query-keys- Query key factories and organizationrq-query-functions- Query functions that throw on errorsrq-enabled-option- Conditional queries withenabledrq-select-transform- Data transformation withselectrq-query-options- queryOptions, mutationOptions and skipToken
2. Mutation & Updates (CRITICAL)
rq-mutation-setup- useMutation setuprq-mutation-callbacks- onSuccess, onError, onSettledrq-optimistic-updates- Optimistic updates with rollbackrq-mutation-variables- Typed mutation variablesrq-mutation-side-effects- Side effects and cache updates after mutations
3. Zustand Stores (CRITICAL)
zs-create-store- Typed stores, selectors anduseShallowzs-persist- Persist middleware withpartialize(never persist secrets)
4. Advanced Queries (HIGH)
rq-infinite-queries- Infinite scrolling with useInfiniteQueryrq-paginated-queries- Pagination withplaceholderData: keepPreviousDatarq-dependent-queries- Dependent (sequential) queriesrq-parallel-queries- Parallel queries and useQueriesrq-query-cancellation- Query cancellation with AbortSignalrq-suspense-mode- useSuspenseQuery and Suspense boundaries
5. Cache & Performance (HIGH-MEDIUM)
rq-stale-time- Configure staleTimerq-cache-time- Configure gcTime (formerly cacheTime)rq-query-invalidation- Invalidate queriesrq-prefetching- Prefetch datarq-retry-logic- Retry configurationrq-placeholder-data- Placeholder datarq-initial-data- Initial data and cache seedingrq-refetch-options- Refetch configuration
React Query Patterns
Setup
// lib/queryClient.ts
import { QueryClient } from '@tanstack/react-query'
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 1000 * 60 * 5, // 5 minutes
gcTime: 1000 * 60 * 30, // 30 minutes (formerly cacheTime)
retry: 1,
refetchOnWindowFocus: false,
},
},
})
// App.tsx
import { QueryClientProvider } from '@tanstack/react-query'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import { queryClient } from './lib/queryClient'
function App() {
return (
<QueryClientProvider client={queryClient}>
<Router />
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
)
}
Query Keys Factory
// lib/queryKeys.ts
export const queryKeys = {
// All posts
posts: {
all: ['posts'] as const,
lists: () => [...queryKeys.posts.all, 'list'] as const,
list: (filters: PostFilters) =>
[...queryKeys.posts.lists(), filters] as const,
details: () => [...queryKeys.posts.all, 'detail'] as const,
detail: (id: number) => [...queryKeys.posts.detail
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- AGENTS.md
- README.md
- metadata.json
- rules/_sections.md
- rules/_template.md
- rules/rq-cache-time.md
- rules/rq-dependent-queries.md
- rules/rq-enabled-option.md
- rules/rq-infinite-queries.md
- rules/rq-initial-data.md
- rules/rq-mutation-callbacks.md
- rules/rq-mutation-setup.md
- rules/rq-mutation-side-effects.md
- rules/rq-mutation-variables.md
- rules/rq-optimistic-updates.md
- rules/rq-paginated-queries.md
- rules/rq-parallel-queries.md
- rules/rq-placeholder-data.md
- rules/rq-prefetching.md
- rules/rq-query-cancellation.md
- rules/rq-query-functions.md
- rules/rq-query-invalidation.md
- rules/rq-query-keys.md
- rules/rq-query-options.md
- rules/rq-refetch-options.md
- rules/rq-retry-logic.md
- rules/rq-select-transform.md
- rules/rq-stale-time.md
- rules/rq-suspense-mode.md
- rules/rq-usequery.md
- rules/zs-create-store.md
- rules/zs-persist.md
FAQ
Что делает скилл state-management?
React Query and Zustand patterns for state management. Use when implementing data fetching, caching, mutations, or client-side state. Triggers on tasks involving useQuery, useMutation, Zustand stores, caching, or state management.
Как установить скилл state-management?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл state-management запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
AnthropicCreate 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…
discernment-nudge
AnthropicAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
data-consolidate
AnthropicJoins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
inspection-to-capa
AnthropicRuns the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
