Frontend · Skill
Configure React state
configure-react-state
Chooses the home for React state - local useState, a provider for theme, a small Zustand store, or a server cache such as React Query. Use when the user needs Zustand, a shared client value, or is copying server data into a global store.
Works with: Any AI Not yet model-tested; testing Jan 2027
Paste it into ChatGPT, Claude, Gemini or any AI chat, then tell it about your project. How it works
Install in Claude Code, Cursor or Codex (optional)
Only for AI coding tools that read skill folders. Run one line in a terminal, in your project folder. It downloads this skill's text files from TheSkillVault and nothing else; you can read them first with “View raw SKILL.md”.
Claude Code (all your projects)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/configure-react-state/raw' -o ~/'.claude/skills/configure-react-state/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/configure-react-state/files/LICENSE.txt' -o ~/'.claude/skills/configure-react-state/LICENSE.txt'Cursor (this project)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/configure-react-state/raw' -o '.cursor/skills/configure-react-state/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/configure-react-state/files/LICENSE.txt' -o '.cursor/skills/configure-react-state/LICENSE.txt'Codex and other Agent Skills tools (this project)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/configure-react-state/raw' -o '.agents/skills/configure-react-state/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/configure-react-state/files/LICENSE.txt' -o '.agents/skills/configure-react-state/LICENSE.txt'
Or connect the whole library over MCP
Add TheSkillVault to Cursor or add this to your app's MCP settings (read-only; help):
{
"mcpServers": {
"theskillvault": {
"url": "https://theskillvault.ai/mcp"
}
}
}Most React state belongs next to the component that draws it. Add a store only when distant parts of the page must share a client value. Server data is not client state.
When to use
- A value is copied into a store and then drifts away from the server.
- Many components need the same client value, such as a cart draft or a panel that is open.
- You are about to add Redux for a form that one component could hold.
When not to use
- The page is slow because of waterfalls or a large download. That is a speed task, not a store task.
- You are picking colours or a layout. State is not involved.
Steps
- List each value. Mark it as UI (open, selected tab), server data (user, posts), or URL (filters that should survive a refresh).
- Keep UI state in
useStateinside the component that uses it. Lift it to the parent only when two children both need it. - Put filters, tabs and search text in the URL, so refresh and share keep them.
- Fetch server data with the server component, or with React Query or SWR on the client. Do not copy that response into Zustand or Redux.
- Add a small store when many distant components need the same client value. Zustand is enough for most screens. Reach for Redux Toolkit only when the update rules are large and many people edit them.
- Use a provider for rare values such as theme or the current locale. Do not put a value that changes on every keystroke into that provider. Every consumer re-renders.
- After the change, click through the screen. The value should update once, and a refresh should not lose URL state.
import { create } from "zustand";
type Cart = { ids: string[]; add: (id: string) => void };
export const useCart = create<Cart>((set) => ({
ids: [],
add: (id) => set((s) => ({ ids: [...s.ids, id] })),
}));
Gotchas
- Do not store passwords, tokens or API keys in state, a provider or
localStorage. - A store that mirrors a fetch will go stale. Invalidate the query instead of writing a second copy.
useEffectthat copies props into state is usually a bug. Render from the props, or from the query.- One global store for every screen becomes a junk drawer. Split by feature.
Portability
These rules work with any React renderer. If you use Vue, the same split is local refs, a small store such as Pinia, and a server cache. If you use SWR instead of React Query, keep server data there and client-only values in the store.
Done when
- Each value has one home: component, URL, server cache or a small store.
- Server records are not copied into the client store.
- No secret is kept in state or browser storage.
Example prompt
"The product list is in Zustand and it goes stale after an edit. Should this be React Query instead, and what stays in the store?"
---
Adapted from "react-state-management" in wshobson/agents (MIT, Copyright (c) 2024 Seth Hobson). See LICENSE.txt.
Bundled files
Licence
Adapted from Seth Hobson (wshobson/agents, react-state-management) (Copyright (c) 2024 Seth Hobson), MIT License. Adapted by TheSkillVault: rewritten as a choice of local, URL, server-cache or small store, with one original Zustand snippet; dropped Redux and Jotai catalogues; added secret handling, gotchas and done-when.
Licence: MIT License. Attribution when you reuse it: Based on work by Seth Hobson (wshobson/agents, react-state-management) (Copyright (c) 2024 Seth Hobson, MIT License), https://github.com/wshobson/agents/tree/7e2fb559cf4b824b27f1fec49fe88f7511066d26/plugins/frontend-mobile-development/skills/react-state-management; adapted by TheSkillVault, https://theskillvault.ai