Form State: Almost Always Local
You'll learn: Why form inputs, validation errors, and draft values belong in local component state, not global stores.
The Core Principle
When building forms in React, you'll be tempted to store every input value, validation error, and draft change in a global state manager (like Redux, Zustand, or Context). Resist this urge. Form state is inherently temporary and UI-specific—it only matters to that one component until the user submits.
Think of a form like a scratch pad: you scribble notes (type values), check your work (validation), and only when you're done do you file the paper away (submit to server/global state). You wouldn't photocopy every pencil stroke and distribute it to the whole office.
What Belongs Locally
- Input values:
username,email,passwordwhile typing - Validation errors: "Email is invalid" messages
- Draft state: Unsaved changes, toggles, intermediate selections
- UI concerns: Which field is focused, show/hide password
These change rapidly, are only relevant during editing, and disappear or transform after submission.
What Goes Global (If Anything)
- Submitted data: After validation passes and the user clicks "Save"
- Fetched defaults: Pre-filling from a server (but even this can be props!)
Use useState in the form component. Only promote to Context or global state when multiple distant components need the submitted result.
The Anti-Pattern
Storing every keystroke in Redux creates unnecessary rerenders across your app, complicates time-travel debugging with noise, and couples your form to global architecture.
Key Takeaway: Form state is local until proven otherwise—keep inputs, errors, and drafts in useState and only elevate submitted, validated data to global state if sharing is required.