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
{/* TODO T164397693: link to actions documentation once it exists */}
37
37
38
-
Call `useActionState` at the top level of your component to create component state that is updated [when a form action is invoked](/reference/react-dom/components/form). You pass `useActionState` an existing form action function as well as an initial state, and it returns a new action that you use in your form, along with the latest form state. The latest form state is also passed to the function that you provided.
38
+
Call `useActionState` at the top level of your component to create component state that is updated [when a form action is invoked](/reference/react-dom/components/form). You pass `useActionState` an existing form action function as well as an initial state, and it returns a new action that you use in your form, along with the latest form state and whether the Action is still pending. The latest form state is also passed to the function that you provided.
39
39
40
40
```js
41
41
import { useActionState } from"react";
@@ -71,10 +71,11 @@ If used with a Server Action, `useActionState` allows the server's response from
71
71
72
72
#### Returns {/*returns*/}
73
73
74
-
`useActionState` returns an array with exactly two values:
74
+
`useActionState` returns an array with the following values:
75
75
76
76
1. The current state. During the first render, it will match the `initialState` you have passed. After the action is invoked, it will match the value returned by the action.
77
77
2. A new action that you can pass as the `action` prop to your `form` component or `formAction` prop to any `button` component within the form.
78
+
3. The `isPending` flag that tells you whether there is a pending Transition.
78
79
79
80
#### Caveats {/*caveats*/}
80
81
@@ -104,10 +105,11 @@ function MyComponent() {
104
105
}
105
106
```
106
107
107
-
`useActionState` returns an array with exactly two items:
108
+
`useActionState` returns an array with the following items:
108
109
109
110
1. The <CodeStep step={1}>current state</CodeStep> of the form, which is initially set to the <CodeStep step={4}>initial state</CodeStep> you provided, and after the form is submitted is set to the return value of the <CodeStep step={3}>action</CodeStep> you provided.
110
111
2. A <CodeStep step={2}>new action</CodeStep> that you pass to `<form>` as its `action` prop.
112
+
3. A <CodeStep step={1}>pending state</CodeStep> that you can utilise whilst your action is processing.
111
113
112
114
When the form is submitted, the <CodeStep step={3}>action</CodeStep> function that you provided will be called. Its return value will become the new <CodeStep step={1}>current state</CodeStep> of the form.
0 commit comments