[form] Document onSubmit event handler alongside action#1
Closed
aurorascharff wants to merge 2 commits into
Closed
[form] Document onSubmit event handler alongside action#1aurorascharff wants to merge 2 commits into
aurorascharff wants to merge 2 commits 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! 🙌 |
There was a problem hiding this comment.
Pull request overview
This PR updates the <form> reference page to document classic client-side form submission via onSubmit (with preventDefault() + FormData), alongside the existing action-first approach, to avoid implying that action is the only valid client-side pattern.
Changes:
- Added a new first Usage section: “Handle form submission with an event handler” with an
onSubmit+FormDataSandpack example. - Added a
<Note>contrastingonSubmitvsaction(event access vs enhanced features likeuseFormStatusand Server Functions). - Renamed and clarified the existing client submission section to be explicitly about
action, including that it runs in a Transition and doesn’t needpreventDefault().
Docs review checklist (docs-writer-reference / docs-voice / docs-components / docs-sandpack)
-
docs-writer-reference
- form.md:63-66 — Example style differs from the established
onSubmit+FormDatapattern used on related pages (storee.targetinformbeforenew FormData(form)). - form.md:86 — Heading could be clearer by explicitly referencing the
actionprop (to avoid reading as the HTMLactionattribute).
- form.md:63-66 — Example style differs from the established
-
docs-voice
- form.md:82 — Use singular “pending state” (matches the rest of the page’s phrasing).
-
docs-components
- form.md:80-84 —
<Note>spacing/structure matches component rules (blank line after opening tag, no consecutive callouts introduced).
- form.md:80-84 —
-
docs-sandpack
- form.md:57-76 — Sandpack uses
export default, function declarations, andeas event parameter; no hydration pitfalls observed.
- form.md:57-76 — Sandpack uses
Please create a plan to address the unchecked items above.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rickhanlonii
approved these changes
Jun 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
The
<form>reference page documented form submission only through theactionprop. The classic event-handler approach —onSubmit+e.preventDefault()+new FormData(e.target)— was missing entirely, even though it's still fully valid and is the pattern shown on every related page (<input>,<select>,<textarea>, and throughout Learn).This left readers with the impression that
actionis the only way to handle submission on the client, which isn't true.Changes
onSubmitpattern (matching the example style already used on the<input>/<select>/<textarea>pages).<Note>contrasting the two approaches:onSubmitworks in every version and gives direct event access;actionbuilds on it with form resets,useFormStatus, and Server Functions.actionruns in a Transition and doesn't needpreventDefault().The Server Function, pending state, optimistic update, error handling, and multiple-submission sections are genuinely action-specific and left unchanged.