Repository navigation
docs: explain how to preserve form state after submission - #8465
rylansedlacek wants to merge 1 commit into
Conversation
Size changesDetails📦 Next.js Bundle Analysis for react-devThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
MaxwellCohen
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
This line is incorrect because HTML forms, by default, reset the page/form. We can see it at the event.preventDefault(); in line 94
|
Thanks for the contribution! #8512 has been merged and addresses these concerns. If you have further suggestions, please open a new PR and tag me and I’ll take a look! |
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
onSubmittogether withstartTransitionto preserve form values while still using transitions.Resolves #8397