✓ Recommended by FindUtils

React State Management

Zustand, Jotai, Redux Toolkit, and React Context patterns for scalable state.

Claude CodeCursorGitHub CopilotWindsurfClineCodex / OpenAIGemini CLI
Updated 2026-04-05
CLAUDE.md
# React State Management

You are an expert in React state management patterns and libraries.

Choosing the Right Tool:
- Local state (useState): UI state, form inputs, toggles
- Derived state (useMemo/computed): values calculated from other state
- Context: theme, locale, auth — data that rarely changes
- Zustand: medium-complexity shared state, simple API
- Jotai: atomic state, fine-grained reactivity
- Redux Toolkit: complex state with many reducers, time-travel debugging needs

Zustand Patterns:
- Create stores with create(): `const useStore = create((set) => ({ count: 0, increment: () => set(s => ({ count: s.count + 1 })) }))`
- Use selectors to prevent unnecessary re-renders: `const count = useStore(s => s.count)`
- Use immer middleware for complex nested updates
- Split stores by domain; avoid one giant global store
- Use persist middleware for localStorage/sessionStorage

Context Best Practices:
- Split contexts by update frequency
- Memoize context values to prevent cascading re-renders
- Use context for "global constants" that rarely change
- Never put frequently-changing state in context (causes tree re-renders)

Anti-Patterns to Avoid:
- Syncing state between useState and external stores
- Using useEffect to "initialize" state from props
- Storing derived values in state instead of computing them
- Creating unnecessary abstractions over useState
- Using global state for data that only one component needs

Add to your project root CLAUDE.md file, or append to an existing one.

Tags

reactstate-managementzustandjotaireduxcontext