Forms and controlled inputs
Forms are how users give your app data: sign-ups, searches, checkouts and settings. In React, the standard approach is controlled inputs, where React state is the single source of truth for what's in each field.
A controlled input
The loop is: state → value shown in the input → the user types → onChange → setName → re-render with the new value. Because React controls the value, you can transform it, validate it, or reset it at any time.
Different input types
| Input | Controlled with |
|---|---|
| text, email, password, textarea, select | value + onChange |
| checkbox | checked + onChange (read e.target.checked) |
| radio | checked={state === value} + onChange |
Submitting and validating
Good form UX: show errors after the user leaves a field (onBlur), or on submit, not while they're halfway through typing.
Uncontrolled inputs and FormData
For simple forms you can let the browser hold the values, and read them all on submit. This is the approach React 19's form actions (and Next.js Server Actions) are built around:
defaultValue sets the starting value without React controlling the input.
React 19: form actions and useActionState
React 19 lets you pass a function to <form action={…}>. It receives the FormData, and useActionState tracks the result and a pending flag for async work:
You'll use exactly this pattern with Server Actions in the Next.js track.
Libraries for big forms
For complex forms (many fields, nested data, async validation), teams use React Hook Form plus Zod for schema validation. They take care of performance and the boilerplate.
Practice: checkout form
Build a checkout form with name, email, a delivery option (radio buttons: standard ₹0 / express ₹99) and a "gift wrap" checkbox (₹49). Show a live order total (base ₹999 + extras). Disable the submit button until name and email are valid, and show a summary after submitting.
1.What makes an input "controlled"?
2.Why call e.preventDefault() in an onSubmit handler?