Skip to content

Fix Server Function examples for Actions, forms, and useActionState - #8538

Open
smith558 wants to merge 7 commits into
reactjs:mainfrom
smith558:patch-13
Open

Fix Server Function examples for Actions, forms, and useActionState#8538
smith558 wants to merge 7 commits into
reactjs:mainfrom
smith558:patch-13

Conversation

@smith558

@smith558 smith558 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #8537.

The Server Functions reference reused one updateName function across examples that invoke it with different arguments. This PR gives each usage a compatible Server Function and completes the corresponding client examples:

  • A client Action passes the current name and handles the Server Function's returned error.
  • A Server Function passed to the <form> action prop receives the submitted FormData.
  • A Server Function passed to useActionState receives the previous state and submitted FormData, then returns the next state.
  • The permalink example explains the browser navigation that occurs when a form is submitted before JavaScript loads.

The PR also clarifies Server Function references, form reset behavior, Action terminology, pending state, and the boundary between server and client files.

@github-actions

Copy link
Copy Markdown

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! 🙌

@MaxwellCohen

MaxwellCohen commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Hi,

I am getting a client-side error on the server functions preview. This is usually caused by a misalignment of line numbers for function highlights.

Screenshot_20260719_082731_Chrome

Edit: This has been fixed!

@smith558

Copy link
Copy Markdown
Contributor Author

@MaxwellCohen thanks, will fix

Corrected the index of 'submitAction' in the code snippet.
@smith558

Copy link
Copy Markdown
Contributor Author

@MaxwellCohen fixed

@smith558

smith558 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

@MaxwellCohen @rickhanlonii @aurorascharff 🙂 please review

… transition comment

- Convert the remaining two Usage headings to gerund form to match the
  rest of the page and react.dev convention (anchors unchanged)
- Reset wording: "succeeds" + "the form's uncontrolled fields" (aligns with reactjs#8512)
- Comment the startTransition-after-await; bump CodeStep line accordingly

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Server Functions work with the new Form features in React 19.

You can pass a Server Function to a Form to automatically submit the form to the server:
You can pass a Server Function to a Form to automatically submit the form to the server. React passes the submitted `FormData` to the Server Function as its first argument:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we should add a link to MDN form data here so that users can see what is included in the form data
FormData link so users know what functions are available.

Suggested change
You can pass a Server Function to a Form to automatically submit the form to the server. React passes the submitted `FormData` to the Server Function as its first argument:
You can pass a Server Function to a Form to automatically submit the form to the server. React passes the submitted `[FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData)` to the Server Function as its first argument:

```

When the <CodeStep step={2}>permalink</CodeStep> is provided to `useActionState`, React will redirect to the provided URL if the form is submitted before the JavaScript bundle loads.
When the <CodeStep step={2}>permalink</CodeStep> is provided to `useActionState`, the browser will navigate to the provided URL if the form is submitted before the JavaScript bundle loads. At the destination, render `useActionState` with the same Server Function and permalink so React can pass the returned state to it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❤️ I really like pointing out that this is browser behavior, not React behavior.

### Server Functions with `useActionState` {/*server-functions-with-use-action-state*/}
### Calling a Server Function with `useActionState` {/*server-functions-with-use-action-state*/}

You can call Server Functions with `useActionState` for the common case where you just need access to the action pending state and last returned response. The Server Function receives the previous state as its first argument and the submitted `FormData` as its second argument. Its return value becomes the next state:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
You can call Server Functions with `useActionState` for the common case where you just need access to the action pending state and last returned response. The Server Function receives the previous state as its first argument and the submitted `FormData` as its second argument. Its return value becomes the next state:
You can call Server Functions with `useActionState` for the common case where you need access to the Action's pending state and the last returned response. The Server Function receives the previous state as its first argument and the submitted `[FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData)` as its second argument. Its return value becomes the next state:

@aurorascharff aurorascharff changed the title Fix Server Functions documentation examples Fix Server Function examples for Actions, forms, and useActionState Sep 8, 2026
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.

[Mistakes]: Server Functions examples use incompatible action signatures

3 participants