State Management with Claude Code
Claude handles React state well but reaches for the wrong tool by default. Here's how to steer it toward the right choice.
React state management is an area where Claude Code produces correct code that isn't always the right code. Claude knows useState, useReducer, Context, and external stores — and it has opinions about when to use each. Those opinions are sometimes wrong for your specific situation.
The default problem: over-engineering
For complex-looking state, Claude's default is to suggest external state management (Zustand, Jotai, Redux) before simpler options are ruled out. Sometimes that's right. Often the state is local to a component tree and Context or even plain useState would work fine.
Adding to any state management prompt: "Use the simplest solution that works. Only suggest external state management if local state genuinely isn't sufficient" changes the output.
When Claude's default is correct
For state that needs to be accessed from many disconnected components across the component tree, external state management is the right call. Claude correctly identifies this pattern. For cross-cutting concerns like auth state, theme, and user preferences, a lightweight external store makes sense and Claude will implement it cleanly.
When local state is actually enough
If the state only matters to a component and its children, useState plus props or a simple useReducer is almost always the right answer. Claude will sometimes suggest Context even for state that doesn't need to be global — give it explicit scope: "This state is only needed within this component and its direct children."
useReducer vs useState
Claude reaches for useReducer when state has multiple sub-values that change together. This is often the right call, but the resulting code is more complex. For three or four related pieces of state that change together, useReducer is usually correct. For one or two values, useState with explicit setters is simpler and Claude will produce it if you ask.
The server state question
For data fetched from an API, ask Claude whether it's suggesting client state management or server state management. React Query and SWR handle server state differently than Zustand handles local state — they're not interchangeable. Claude knows both but will pick based on context cues you might not intend to give.