{"name":"configure-react-state","description":"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.","category":"frontend","tags":["react","state"],"models":["any"],"proven":false,"passing_families":0,"model_testing":"Not yet model-tested; testing Jan 2027","url":"https://theskillvault.ai/skills/configure-react-state","api_url":"https://theskillvault.ai/api/skills/configure-react-state","raw_url":"https://theskillvault.ai/api/skills/configure-react-state/raw","body":"# Configure React state\n\nMost 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.\n\n## When to use\n- A value is copied into a store and then drifts away from the server.\n- Many components need the same client value, such as a cart draft or a panel that is open.\n- You are about to add Redux for a form that one component could hold.\n\n## When not to use\n- The page is slow because of waterfalls or a large download. That is a speed task, not a store task.\n- You are picking colours or a layout. State is not involved.\n\n## Steps\n1. List each value. Mark it as UI (open, selected tab), server data (user, posts), or URL (filters that should survive a refresh).\n2. Keep UI state in `useState` inside the component that uses it. Lift it to the parent only when two children both need it.\n3. Put filters, tabs and search text in the URL, so refresh and share keep them.\n4. 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.\n5. 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.\n6. 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.\n7. After the change, click through the screen. The value should update once, and a refresh should not lose URL state.\n\n```ts\nimport { create } from \"zustand\";\n\ntype Cart = { ids: string[]; add: (id: string) => void };\nexport const useCart = create<Cart>((set) => ({\n  ids: [],\n  add: (id) => set((s) => ({ ids: [...s.ids, id] })),\n}));\n```\n\n## Gotchas\n- Do not store passwords, tokens or API keys in state, a provider or `localStorage`.\n- A store that mirrors a fetch will go stale. Invalidate the query instead of writing a second copy.\n- `useEffect` that copies props into state is usually a bug. Render from the props, or from the query.\n- One global store for every screen becomes a junk drawer. Split by feature.\n\n## Portability\nThese 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.\n\n## Done when\n- Each value has one home: component, URL, server cache or a small store.\n- Server records are not copied into the client store.\n- No secret is kept in state or browser storage.\n\n## Example prompt\n\"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?\"\n\n---\nAdapted from \"react-state-management\" in wshobson/agents (MIT, Copyright (c) 2024 Seth Hobson). See LICENSE.txt.","files":["LICENSE.txt"],"license":"MIT","license_name":"MIT License","license_url":"https://opensource.org/license/mit","attribution":"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","install":{"claude_code":"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":"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'","agents":"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'","mcp_url":"https://theskillvault.ai/mcp","cursor_mcp_deeplink":"cursor://anysphere.cursor-deeplink/mcp/install?name=theskillvault&config=eyJ1cmwiOiJodHRwczovL3RoZXNraWxsdmF1bHQuYWkvbWNwIn0%3D","mcp_config":{"mcpServers":{"theskillvault":{"url":"https://theskillvault.ai/mcp"}}}},"bundles":[],"tested_on":[{"family":"chatgpt","name":"ChatGPT","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"claude","name":"Claude","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"gemini","name":"Gemini","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"grok","name":"Grok","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"llama","name":"Llama","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"deepseek","name":"DeepSeek","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"mistral","name":"Mistral","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"qwen","name":"Qwen","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"kimi","name":"Kimi K","outcome":null,"date":null,"source":null,"counts":false,"stale":false}],"proven_rule":{"threshold":5,"window_days":365,"computed_at":"2026-11-29T03:42:30.374Z"}}