You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Part of #6713: capitalize React-specific concepts across the docs. This PR covers "Actions" (including Server Actions and form actions) with per-occurrence judgment per the style guide. Blog and community pages excluded; code spans, URL fragments, and heading anchors untouched.
## Flight Data Types in Server Actions {/*flight-data-types-actions*/}
288
288
289
-
This demo sends Map, Set, Date, and BigInt from a client component *to* a server action via `encodeReply`/`decodeReply`, then verifies the types survived the round trip.
289
+
This demo sends Map, Set, Date, and BigInt from a client component *to* a Server Action via `encodeReply`/`decodeReply`, then verifies the types survived the round trip.
## Server Action Mutation + Re-render {/*action-mutation-rerender*/}
392
392
393
-
The server action mutates server-side data and returns a confirmation string. The updated list is only visible because the framework automatically re-renders the entire server component tree after the action completes — the server component re-reads the data and streams the new UI to the client.
393
+
The Server Action mutates server-side data and returns a confirmation string. The updated list is only visible because the framework automatically re-renders the entire server component tree after the Action completes — the server component re-reads the data and streams the new UI to the client.
## Inline Server Actions {/*inline-server-actions*/}
489
489
490
-
Server actions defined inline inside a server component with `'use server'` on the function body. The action closes over module-level state and is passed as a prop — no separate `actions.js` file needed.
490
+
Server Actions defined inline inside a server component with `'use server'` on the function body. The Action closes over module-level state and is passed as a prop — no separate `actions.js` file needed.
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/components/form.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,7 +86,7 @@ Reading form data with `onSubmit` works in every version of React and gives you
86
86
87
87
</Note>
88
88
89
-
### Handle form submission with an action prop {/*handle-form-submission-with-an-action-prop*/}
89
+
### Handle form submission with an Action prop {/*handle-form-submission-with-an-action-prop*/}
90
90
91
91
Pass a function to the `action` prop of form to run the function when the form is submitted. [`formData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) will be passed to the function as an argument so you can access the data submitted by the form. This differs from the conventional [HTML action](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#action), which only accepts URLs. Unlike `onSubmit`, an `action` runs in a [Transition](/reference/react/useTransition) and calling `e.preventDefault()` isn't needed. After the `action` function succeeds, all uncontrolled field elements in the form are reset.
92
92
@@ -115,7 +115,7 @@ Render a `<form>` with an input and submit button. Pass a Server Function (a fun
115
115
116
116
Passing a Server Function to `<form action>` allow users to submit forms without JavaScript enabled or before the code has loaded. This is beneficial to users who have a slow connection, device, or have JavaScript disabled and is similar to the way forms work when a URL is passed to the `action` prop.
117
117
118
-
You can use hidden form fields to provide data to the `<form>`'s action. The Server Function will be called with the hidden form field data as an instance of [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData).
118
+
You can use hidden form fields to provide data to the `<form>`'s Action. The Server Function will be called with the hidden form field data as an instance of [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData).
119
119
120
120
```jsx
121
121
import { updateCart } from'./lib.js';
@@ -136,7 +136,7 @@ function AddToCart({productId}) {
136
136
}
137
137
```
138
138
139
-
In lieu of using hidden form fields to provide data to the `<form>`'s action, you can call the <CodeStepstep={1}>`bind`</CodeStep> method to supply it with extra arguments. This will bind a new argument (<CodeStepstep={2}>`productId`</CodeStep>) to the function in addition to the <CodeStepstep={3}>`formData`</CodeStep> that is passed as an argument to the function.
139
+
In lieu of using hidden form fields to provide data to the `<form>`'s Action, you can call the <CodeStepstep={1}>`bind`</CodeStep> method to supply it with extra arguments. This will bind a new argument (<CodeStepstep={2}>`productId`</CodeStep>) to the function in addition to the <CodeStepstep={3}>`formData`</CodeStep> that is passed as an argument to the function.
@@ -320,7 +320,7 @@ Displaying a form submission error message before the JavaScript bundle loads fo
320
320
1. the function passed to the `<form>`'s `action` prop be a [Server Function](/reference/rsc/server-functions)
321
321
1. the `useActionState` Hook be used to display the error message
322
322
323
-
`useActionState` takes two parameters: a [Server Function](/reference/rsc/server-functions) and an initial state. `useActionState` returns two values, a state variable and an action. The action returned by `useActionState` should be passed to the `action` prop of the form. The state variable returned by `useActionState` can be used to display an error message. The value returned by the Server Function passed to `useActionState` will be used to update the state variable.
323
+
`useActionState` takes two parameters: a [Server Function](/reference/rsc/server-functions) and an initial state. `useActionState` returns two values, a state variable and an Action. The Action returned by `useActionState` should be passed to the `action` prop of the form. The state variable returned by `useActionState` can be used to display an error message. The value returned by the Server Function passed to `useActionState` will be used to update the state variable.
324
324
325
325
<Sandpack>
326
326
@@ -368,13 +368,13 @@ export async function signUpNewUser(newEmail) {
368
368
369
369
</Sandpack>
370
370
371
-
Learn more about updating state from a form action with the [`useActionState`](/reference/react/useActionState) docs
371
+
Learn more about updating state from a form Action with the [`useActionState`](/reference/react/useActionState) docs
Forms can be designed to handle multiple submission actions based on the button pressed by the user. Each button inside a form can be associated with a distinct action or behavior by setting the `formAction` prop.
375
+
Forms can be designed to handle multiple submission Actions based on the button pressed by the user. Each button inside a form can be associated with a distinct Action or behavior by setting the `formAction` prop.
376
376
377
-
When a user taps a specific button, the form is submitted, and a corresponding action, defined by that button's attributes and action, is executed. For instance, a form might submit an article for review by default but have a separate button with `formAction` set to save the article as a draft.
377
+
When a user taps a specific button, the form is submitted, and a corresponding Action, defined by that button's attributes and Action, is executed. For instance, a form might submit an article for review by default but have a separate button with `formAction` set to save the article as a draft.
Copy file name to clipboardExpand all lines: src/content/reference/react/useActionState.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,7 @@ function MyCart({initialState}) {
60
60
* The `dispatchAction` function has a stable identity, so you will often see it omitted from Effect dependencies, but including it will not cause the Effect to fire. If the linter lets you omit a dependency without errors, it is safe to do. [Learn more about removing Effect dependencies.](/learn/removing-effect-dependencies#move-dynamic-objects-and-functions-inside-your-effect)
61
61
* When using the `permalink` option, ensure the same form component is rendered on the destination page (including the same `reducerAction` and `permalink`) so React knows how to pass the state through. Once the page becomes interactive, this parameter has no effect.
62
62
* When using Server Functions, `initialState` needs to be [serializable](/reference/rsc/use-server#serializable-parameters-and-return-values) (values like plain objects, arrays, strings, and numbers).
63
-
* If `dispatchAction` throws an error, React cancels all queued actions and shows the nearest [Error Boundary](/reference/react/Component#catching-rendering-errors-with-an-error-boundary).
63
+
* If `dispatchAction` throws an error, React cancels all queued Actions and shows the nearest [Error Boundary](/reference/react/Component#catching-rendering-errors-with-an-error-boundary).
64
64
* If there are multiple ongoing Actions, React batches them together. This is a limitation that may be removed in a future release.
65
65
66
66
<Note>
@@ -269,7 +269,7 @@ Try clicking "Add Ticket" multiple times. Every time you click, a new `addToCart
269
269
270
270
We have to wait for the previous result of `addToCartAction` in order to pass the `prevCount` to the next call to `addToCartAction`. That means React has to wait for the previous Action to finish before calling the next Action.
271
271
272
-
You can typically solve this by [using with useOptimistic](/reference/react/useActionState#using-with-useoptimistic) but for more complex cases you may want to consider [cancelling queued actions](#cancelling-queued-actions) or not using `useActionState`.
272
+
You can typically solve this by [using with useOptimistic](/reference/react/useActionState#using-with-useoptimistic) but for more complex cases you may want to consider [cancelling queued Actions](#cancelling-queued-actions) or not using `useActionState`.
273
273
274
274
</DeepDive>
275
275
@@ -1423,7 +1423,7 @@ function action(prevState, formData) {
1423
1423
1424
1424
---
1425
1425
1426
-
### My actions are being skipped {/*actions-skipped*/}
1426
+
### My Actions are being skipped {/*actions-skipped*/}
1427
1427
1428
1428
If you call `dispatchAction` multiple times and some of them don't run, it may be because an earlier `dispatchAction` call threw an error.
These solutions handle request ordering for you. When using Transitions to build your own custom hooks or libraries that manage async state transitions, you have greater control over the request ordering, but you must handle it yourself.
When exposing an `action` prop from a component, you should `await` it inside the transition.
750
750
751
-
This allows the `action` callback to be either synchronous or asynchronous without requiring an additional `startTransition` to wrap the `await` in the action.
751
+
This allows the `action` callback to be either synchronous or asynchronous without requiring an additional `startTransition` to wrap the `await` in the Action.
752
752
753
753
</Note>
754
754
@@ -1256,7 +1256,7 @@ This is recommended for three reasons:
1256
1256
1257
1257
- [Transitions are interruptible,](#perform-non-blocking-updates-with-actions) which lets the user click away without waiting for the re-render to complete.
1258
1258
- [Transitions prevent unwanted loading indicators,](#preventing-unwanted-loading-indicators) which lets the user avoid jarring jumps on navigation.
1259
-
- [Transitions wait for all pending actions](#perform-non-blocking-updates-with-actions) which lets the user wait for side effects to complete before the new page is shown.
1259
+
- [Transitions wait for all pending Actions](#perform-non-blocking-updates-with-actions) which lets the user wait for side effects to complete before the new page is shown.
1260
1260
1261
1261
Here is a simplified router example using Transitions for navigations.
1262
1262
@@ -1957,7 +1957,7 @@ export async function updateQuantity(newName) {
1957
1957
1958
1958
When clicking multiple times, it's possible for previous requests to finish after later requests. When this happens, React currently has no way to know the intended order. This is because the updates are scheduled asynchronously, and React loses context of the order across the async boundary.
1959
1959
1960
-
This is expected, because Actions within a Transition do not guarantee execution order. For common use cases, React provides higher-level abstractions like [`useActionState`](/reference/react/useActionState) and [`<form>`actions](/reference/react-dom/components/form) that handle ordering for you. For advanced use cases, you'll need to implement your own queuing and abort logic to handle this.
1960
+
This is expected, because Actions within a Transition do not guarantee execution order. For common use cases, React provides higher-level abstractions like [`useActionState`](/reference/react/useActionState) and [`<form>`Actions](/reference/react-dom/components/form) that handle ordering for you. For advanced use cases, you'll need to implement your own queuing and abort logic to handle this.
1961
1961
1962
1962
1963
1963
Example of `useActionState` handling execution order:
Copy file name to clipboardExpand all lines: src/content/reference/rsc/server-functions.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ title: Server Functions
6
6
7
7
Server Functions are for use in [React Server Components](/reference/rsc/server-components).
8
8
9
-
**Note:** Until September 2024, we referred to all Server Functions as "Server Actions". If a Server Function is passed to an action prop or called from inside an action then it is a Server Action, but not all Server Functions are Server Actions. The naming in this documentation has been updated to reflect that Server Functions can be used for multiple purposes.
9
+
**Note:** Until September 2024, we referred to all Server Functions as "Server Actions". If a Server Function is passed to an Action prop or called from inside an Action then it is a Server Action, but not all Server Functions are Server Actions. The naming in this documentation has been updated to reflect that Server Functions can be used for multiple purposes.
10
10
11
11
</RSC>
12
12
@@ -176,7 +176,7 @@ For more, see the docs for [Server Functions in Forms](/reference/rsc/use-server
176
176
177
177
### Server Functions with `useActionState` {/*server-functions-with-use-action-state*/}
178
178
179
-
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:
179
+
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:
Copy file name to clipboardExpand all lines: src/content/reference/rsc/use-server.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ Instead of individually marking functions with `'use server'`, you can add the d
44
44
* Because the underlying network calls are always asynchronous, `'use server'` can only be used on async functions.
45
45
* Always treat arguments to Server Functions as untrusted input and authorize any mutations. See [security considerations](#security).
46
46
* Server Functions should be called in a [Transition](/reference/react/useTransition). Server Functions passed to [`<form action>`](/reference/react-dom/components/form#props) or [`formAction`](/reference/react-dom/components/input#props) will automatically be called in a transition.
47
-
* Server Functions are designed for mutations that update server-side state; they are not recommended for data fetching. Accordingly, frameworks implementing Server Functions typically process one action at a time and do not have a way to cache the return value.
47
+
* Server Functions are designed for mutations that update server-side state; they are not recommended for data fetching. Accordingly, frameworks implementing Server Functions typically process one Action at a time and do not have a way to cache the return value.
0 commit comments