React 19 clears uncontrolled fields after a form action finishes, even when it returns a validation error. Here is why, and how to keep what the user typed.
The short answer
#When you pass a function to a form's action prop, React 19 resets the form's uncontrolled fields once the action finishes. It does this even if your action returned an error message, so the user loses what they typed. Return the submitted values from the action and feed them back in as defaultValue, or handle the submission yourself with onSubmit.
_10<input name="email" defaultValue={state.values.email} />
Why it happens
#Form actions are modelled on plain HTML forms. When a normal form submits, the browser loads a new page and the fields start empty. React copies that behaviour: after the action's transition completes, it resets the form, which puts every uncontrolled input back to its defaultValue.
React cannot tell whether a result counts as success in your app. An action that returns an object with an error message has still finished normally, so the reset still happens. Controlled inputs, where you pass value and keep the text in state, are not affected, because React renders them from your state again.
How to fix it
#Return the submitted values and use them as defaultValue
This keeps the fields uncontrolled and works with Server Actions. The action returns what the user entered, and the reset restores each field to that value instead of an empty string.
_24// app/subscribe/actions.ts_24'use server';_24_24export type FormState = {_24 error?: string;_24 values: { name: string; email: string };_24};_24_24export async function subscribe(_24 prevState: FormState,_24 formData: FormData_24): Promise<FormState> {_24 const values = {_24 name: String(formData.get('name') ?? ''),_24 email: String(formData.get('email') ?? ''),_24 };_24_24 if (!values.email.includes('@')) {_24 return { error: 'Please enter a valid email address.', values };_24 }_24_24 await saveSubscriber(values);_24 return { values: { name: '', email: '' } };_24}
_22// app/subscribe/subscribe-form.tsx_22'use client';_22_22import { useActionState } from 'react';_22import { subscribe, type FormState } from './actions';_22_22const initialState: FormState = { values: { name: '', email: '' } };_22_22export function SubscribeForm() {_22 const [state, formAction, isPending] = useActionState(subscribe, initialState);_22_22 return (_22 <form action={formAction}>_22 <input name="name" defaultValue={state.values.name} />_22 <input name="email" type="email" defaultValue={state.values.email} />_22 {state.error && <p role="alert">{state.error}</p>}_22 <button type="submit" disabled={isPending}>_22 Subscribe_22 </button>_22 </form>_22 );_22}
On success the action returns empty values, so the form clears as expected.
Handle the submission with onSubmit
The automatic reset only applies when a function is passed to action. If you call preventDefault in onSubmit and run the work yourself, React leaves the fields alone, and you decide when to clear them:
_30'use client';_30_30import { useTransition, type FormEvent } from 'react';_30import { saveSubscriber } from './actions';_30_30export function SubscribeForm() {_30 const [isPending, startTransition] = useTransition();_30_30 function handleSubmit(event: FormEvent<HTMLFormElement>) {_30 event.preventDefault();_30 const form = event.currentTarget;_30 const formData = new FormData(form);_30_30 startTransition(async () => {_30 const result = await saveSubscriber(formData);_30 if (result.ok) {_30 form.reset();_30 }_30 });_30 }_30_30 return (_30 <form onSubmit={handleSubmit}>_30 <input name="email" type="email" />_30 <button type="submit" disabled={isPending}>_30 Subscribe_30 </button>_30 </form>_30 );_30}
You lose the progressive enhancement that form actions give you, because this form needs JavaScript to submit.
Use controlled inputs for complex forms
If you already keep fields in state for live validation, pass value and onChange. The reset does not change controlled values.
Common pitfalls
#- Passing
valuewithoutonChange. React makes the input read-only and warns in the console. UsedefaultValuefor uncontrolled fields. - Forgetting selects and checkboxes. Use
defaultValueon aselectanddefaultCheckedon a checkbox in the same way. - Sending sensitive fields back to the browser. Do not return passwords or card details in the state; let those fields clear.
- Expecting a new
defaultValueto change a field the user is editing. It only takes effect on first render and when the form resets. - Trying to refill a file input. Browsers do not allow it, so ask the user to choose the file again.
Related reading
#Was this resource helpful?