frontend-state-management
Use when the user asks about state management, where to put state, global state, Redux Toolkit, Zustand, Jotai, Pinia, NgRx, React Context, server state vs…
от j4flmao★ 47 звёзд на GitHub
Установить frontend-state-management в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Frontend State Management
Purpose
Choose and implement the correct state management pattern for each type of state. Server state, client state, local state, and URL state each have their own solution. Never put server state in a global store.
Agent Protocol
Trigger
Exact user phrases: "state management", "global state", "Redux", "Zustand", "Pinia", "NgRx", "React Context", "state architecture", "where to put state", "server state vs client state", "state library".
Input Context
Before activating, verify:
- The framework is known (React, Vue, Angular).
- The type of state being discussed is identified (server data, UI state, form state, URL state).
Output Artifact
No file output. Produces state architecture decision as text.
Response Format
State: {description}
Type: {server/client/URL}
Storage: {local/global/shared}
Library: {specific library}
Location: {file path}
Rationale: {one sentence}
No preamble. No postamble. No explanations. No filler/hedging/transitions. Compress output — why use many token when few do trick.
Completion Criteria
- State type correctly classified (server vs client).
- Decision follows the decision tree below.
- Server state uses a server state library, NOT a global store.
- Global stores are split by domain (one store per feature, not one store for everything).
- Context is used for dependency injection, not state management.
- URL state is not duplicated in component state.
Max Response Length
Per state decision: 7 lines.
State Management Architecture / Decision Trees
State Classification Decision Tree
Where is the source of truth?
|-- On the server (database, API, third-party service) -->
| SERVER STATE
| Library: TanStack Query, SWR, Apollo, RTK Query
| NEVER put in Zustand, Redux, Pinia, or Context
|
|-- On the client (user interaction, UI state) -->
| Is it shared across multiple components?
| |-- NO -->
| | LOCAL STATE
| | React: useState, useReducer
| | Vue: ref, reactive
| | Angular: Component-local signal
| |
| |-- YES -->
| |-- Complex (multiple actions, transitions, side effects)? -->
| | |-- YES -->
| | | COMPLEX STATE (state machine)
| | | Library: XState, Redux Toolkit (slices + thunks), NgRx
| | | Use when: 15+ actions, cross-cutting concerns, middleware needed
| | |
| | |-- NO -->
| | SHARED STATE (simple store)
| | React: Zustand, Jotai, Valtio
| | Vue: Pinia
| | Angular: Signal Store
| |
| |-- Derived / computed from other state?
| COMPUTED STATE
| React: useMemo, Zustand selectors, Jotai derived atoms
| Vue: computed()
| Angular: computed signal
|
|-- In the URL (search params, path, hash) -->
| URL STATE
| Read: useSearchParams, useParams, useLocation
| Write: router.push/replace, searchParams set
| NEVER duplicate URL state in component state
|
|-- On the device (localStorage, IndexedDB, cookies) -->
PERSISTED STATE
Sync to store on init, write back on change
Zod schema validation on read (storage can be tampered)
Global Store Structure Decision Tree
How many pieces of state?
|-- 1-3 related values (auth: user, token, isAuthenticated) -->
| Single small store is fine
|
|-- 4-10 related values -->
| Split by domain if they change independently
| |-- auth: user, token, login, logout
| |-- cart: items, total, addItem, removeItem
| |-- ui: sidebarOpen, theme, modalState
|
|-- 10+ values -->
MUST split by domain
Each store: max 5-7 state properties + associated actions
A store with 20+ properties is a design smell
Workflow
Step 1: Classify State
Is the source of truth on the server?
YES -> Server state -> useQuery / useFetch / Apollo
NO -> Is it shared across multiple components?
NO -> Component local -> useState / ref / signal
YES -> Is it complex (multiple actions, transitions)?
NO -> Simple store -> Zustand / Pinia / Signal Store
YES -> State machine -> XState / Redux Toolkit / NgRx
Step 2: Server State Pattern
function useUsers() {
return useQuery({
queryKey: ['users', { page }],
queryFn: () => api.getUsers({ page }),
staleTime: 30_000,
gcTime: 5 * 60_000,
})
}
Server state rules:
- staleTime prevents unnecessary refetches. Set based on data volatility.
- gcTime keeps data in cache for instant back-navigation.
- Mutations invalidate related queries on success. Never manually set query data.
Step 3: Client State Patterns
// Local state (one component
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/client-state.md
- references/merged-react-zustand-redux-toolkit.md
- references/server-state.md
- references/state-architecture.md
- references/state-comparison.md
- references/state-patterns.md
- references/state-testing.md
FAQ
Что делает скилл frontend-state-management?
Use when the user asks about state management, where to put state, global state, Redux Toolkit, Zustand, Jotai, Pinia, NgRx, React Context, server state vs client state, or components re-rendering from store updates. Produces a state placement decision and store setup. Not for TanStack Query caching details (use frontend-data-fetching).
Как установить скилл frontend-state-management?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл frontend-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…