reactjs / reactjs/react.dev

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

Open
#8,397 1 comment 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: documentation
Dominant language
JavaScript
Stars
11.8k
Forks
7.9k
Avg merge
1d 11h
Merged PRs (30d)
11

Description

Summary

https://github.com/facebook/react/issues/29034 raises concerns about actions resetting forms. There are many use cases where developers would want to prevent the form from resetting. Since React's behavior is not expected to change, the docs should explain to users how to control form resets and preserve the form's previous state.

Page

https://react.dev/reference/react-dom/components/form

Details

I do not know the best way to provide this information. Some suggestions include:

  1. Add a deep dive on when to use onSubmit vs action props.
  2. Include an example of opting out of automatic resets using an example based on @eps1lon comment here: https://github.com/facebook/react/issues/29034#issuecomment-2143595195. The issue has several other workarounds that may or may not be endorsed by the Rect team.
  3. Update the Handling multiple submission types example so that the "Save draft" button will keep the text of the form.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the React

reference page, especially the “Handling multiple submission types” example, and review issue #29034 and the linked comment for the reset behavior and proposed workarounds. Done means the page clearly explains how to preserve form state after submission and includes an agreed, accurate example without endorsing unsupported behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.