React 19 introduces Form Actions - a new way to handle form submissions that simplifies state management and works seamlessly with Server Components.
The Old Way
jsxfunction OldForm() { const [isPending, setIsPending] = useState(false); const [error, setError] = useState(null); async function handleSubmit(e) { e.preventDefault(); setIsPending(true); setError(null); const formData = new FormData(e.target); try { await submitForm(formData); } catch (err) { setError(err.message); } finally { setIsPending(false); } } return ( <form onSubmit={handleSubmit}> {/* ... */} </form> ); }
The New Way with Form Actions
jsxfunction NewForm() { async function submitAction(formData) { // This function receives FormData directly await submitForm(formData); } return ( <form action={submitAction}> <input name="email" type="email" /> <button type="submit">Submit</button> </form> ); }
Key Benefits
- No
e.preventDefault()- React handles it - Automatic FormData - Passed directly to action
- Progressive Enhancement - Forms work without JS
- Pending States - Built-in with
useFormStatus - Server Actions - Works with React Server Components
How It Works
- Pass an async function to the
actionprop - When form submits, React calls your function with
FormData - React automatically handles pending states
- Use
useFormStatusin child components to access pending state
š Learn more: React 19 Blog Post