Skip to content

docs(nextjs-ssr): clarify need for HTML name attribute in form submissions #1574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/framework/react/guides/ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export const ClientComp = () => {
return (
<div>
<input
name="age"
name="age" // must explicitly set the name attribute for the POST request
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to use name={field.name} instead of a new string? Or is there something users should know about what names to choose for the JSX elements?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, you're absolutely right (I feel like an AI assistant with that response 😄)!

Since we have access to the field object on the render prop, we should definitely use name={field.name} rather than hard-coding the name attribute. That's what I'm doing in my own project in the component that uses useFieldContext, but I forgot we have access to the field object here as well. Good catch!

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good, then! Could you check the whole file for the name prop? Once that's committed, I'll merge. The comment is fine for just the first instance of it imo.

type="number"
value={field.state.value}
onChange={(e) => field.handleChange(e.target.valueAsNumber)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const ClientComp = () => {
return (
<div>
<input
name="age"
name="age" // must explicitly set the name attribute for the POST request
type="number"
value={field.state.value}
onChange={(e) => field.handleChange(e.target.valueAsNumber)}
Expand Down