Skip to content

docs: explain how to preserve form state after submission#8465

Open
rylansedlacek wants to merge 1 commit into
reactjs:mainfrom
rylansedlacek:main
Open

docs: explain how to preserve form state after submission#8465
rylansedlacek wants to merge 1 commit into
reactjs:mainfrom
rylansedlacek:main

Conversation

@rylansedlacek
Copy link
Copy Markdown

@rylansedlacek rylansedlacek commented Jun 1, 2026

Form page now explains how to preserve form state after submission when using forms.

In the issue it was mentioned that uncontrolled fields are reset after successful actions, but there is no explanation on how to opt out of that behavior.

This change adds a new section demonstrating how to use onSubmit together with startTransition to preserve form values while still using transitions.

Resolves #8397

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

Copy link
Copy Markdown

@MaxwellCohen MaxwellCohen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for taking an attempt at the issue.

I noticed an inaccuracy with the help text. Forms by default reset, because they refresh the pages or go to another page on submission.

Also, a missing example/section of using actions and useActionState to keep state like this: https://codesandbox.io/p/sandbox/react-dev-forked-3ptf98


</Sandpack>

Using `onSubmit` preserves the browser's default behavior of leaving form values unchanged after submission while still allowing the submission logic to run in a Transition.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is incorrect because HTML forms, by default, reset the page/form. We can see it at the event.preventDefault(); in line 94

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Suggestion]: improve <Form> documentation to explain how to keep form state after submission

2 participants