Fix Server Functions documentation examples#8538
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! 🙌 |
|
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.
Edit: This has been fixed! |
|
@MaxwellCohen thanks, will fix |
Corrected the index of 'submitAction' in the code snippet.
|
@MaxwellCohen fixed |
|
@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: |
There was a problem hiding this comment.
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.
| 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. |
There was a problem hiding this comment.
❤️ 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: |
There was a problem hiding this comment.
| 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: |

Fixes #8537 + minor content improvements