React State Management taste — ChatGPT and Claude.ai prompt
A ruleset for picking React state tools: when to use useState, Zustand, Context and TanStack Query. Helps avoid overbuilt global stores and duplicated state.
Open on GitHubWhat React State Management taste does
This prompt lays out rules for choosing state management in a React app. It starts with local useState, lifting state only when two sibling components genuinely need it. Server data gets treated as a cache through TanStack Query, not dumped into a global store.
Filters, tabs and pagination belong in search params. Shared client state that outgrows a single component tree goes to Zustand. Redux is not recommended for new projects unless the team already relies on its devtools and middleware.
Separate rules cover async status (one union instead of several booleans), forms (React Hook Form with a zod schema), optimistic updates and rollbacks. The prompt pushes for explicit typing of stores and context values with no any. It is an opinionated checklist with confidence scores from 0.70 to 0.95.
What it helps with
- decide between useState, Zustand and Context for a feature
- stop keeping server data in a global store
- move filters and pagination into the URL
- remove state duplicated through useEffect
- type stores without any
Example prompts for the agent
- Paste the prompt into ChatGPT and ask which store to use for a shopping cart
- Give the prompt to Claude.ai and describe a component with filters: where should filter state live
- Ask the assistant to review my code against these rules and point out where state is misplaced
How to install React State Management taste
How to use
Paste the text at the start of a chat or into project instructions
Manually: put the files in place
.claude/commands/prompts.csv.mdQuestions about React State Management taste
How do I install React State Management taste in Claude Code?
Add the prompt to .claude/commands/prompts.csv.md. The prompts.csv command then becomes available in Claude Code.
What does React State Management taste do?
It is a collection of rules for choosing React state tools: when to use local useState, Context, Zustand or TanStack Query. Each rule carries a confidence score.
Can I use this prompt in ChatGPT?
Yes, the prompt works with ChatGPT and Claude.ai. Paste it at the start of a conversation so the assistant follows these rules when giving React advice.
Source text
prompts.csv · CC0-1.0
# React State Management taste - Start with local useState and lift state only when two siblings truly need it. Confidence: 0.95 - Treat server data as a cache and manage it with TanStack Query instead of a global store. Confidence: 0.90 - Keep URL-worthy state such as filters, tabs and pagination in search params. Confidence: 0.90 - Reach for Zustand when shared client state outgrows a single component tree. Confidence: 0.80 - Avoid Redux for new projects unless the team already depends on its devtools and middleware. Confidence: 0.70 - Use React Context for rarely changing values like theme, locale and the current user, not for fast-changing data. Confidence: 0.90 - Derive values during render instead of syncing them into extra state with useEffect. Confidence: 0.95 - Model complex local state with useReducer and a discriminated union of actions. Confidence: 0.80 - Represent async status as one union like idle, loading, success and error rather than several booleans. Confidence: 0.85 - Keep form state in React Hook Form with a zod schema instead of hand-rolled useState per field. Confidence: 0.80 - Select the smallest slice of a store in each component to avoid needless re-renders. Confidence: 0.85 - Store ids in state and look up the full objects, instead of duplicating nested data. Confidence: 0.80 - Use optimistic updates for quick user actions and roll back on error. Confidence: 0.75 - Never mutate state objects in place; return new objects or use Immer for deep updates. Confidence: 0.90 - Keep persisted state small and versioned when saving it to localStorage. Confidence: 0.75 - Reset component state by changing its key instead of writing reset effects. Confidence: 0.80 - Colocate stores with the feature that owns them rather than in one global store folder. Confidence: 0.75 - Type every store and context value explicitly and avoid any in state shapes. Confidence: 0.90
© f · CC0-1.0 · f/prompts.chat