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
{{ message }}
Repository navigation
Commit 0946026
Browse filesBrowse the repository at this point in the historyBrowse files
docs: explain useFormStatus with custom form actions
Closes#8682.
Document when `useFormStatus().pending` is set for a `preventDefault()` submit handler that starts a Transition in the same event, and add a runnable example for a custom form action. The example also notes that this pattern does not reset the form automatically.
Validation: `yarn check-all` and `git diff --check` pass locally. The initial draft was prepared with AI assistance and reviewed against the React DOM tests and issue details.
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/hooks/useFormStatus.md
+58-1Lines changed: 58 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,7 +54,7 @@ In the above example, `Submit` uses this information to disable `<button>` press
54
54
55
55
A `status` object with the following properties:
56
56
57
-
*`pending`: A boolean. If `true`, this means the parent `<form>` is pending submission. Otherwise, `false`.
57
+
*`pending`: A boolean. If `true`, this means the parent `<form>` is pending submission. Otherwise, `false`.`pending` is also `true` while a Transition started from a `submit` event handler is pending, as long as the handler calls `event.preventDefault()` and starts the Transition in the same event.
58
58
59
59
*`data`: An object implementing the [`FormData interface`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) that contains the data the parent `<form>` is submitting. If there is no active submission or no parent `<form>`, it will be `null`.
60
60
@@ -112,6 +112,63 @@ export async function submitForm(query) {
112
112
```
113
113
</Sandpack>
114
114
115
+
### Display a pending state with a custom form action {/*display-a-pending-state-with-a-custom-form-action*/}
116
+
117
+
If you need to handle form submission in an `onSubmit` event handler instead of passing a function to the `<form action>` prop, call `event.preventDefault()` and start a Transition in the same event handler. A component inside the form can then use `useFormStatus` to read the pending state while the action is running.
Unlike a function passed to the `<form action>` prop, handling submission this way does not automatically reset the form.
170
+
171
+
115
172
<Pitfall>
116
173
117
174
##### `useFormStatus` will not return status information for a `<form>` rendered in the same component. {/*useformstatus-will-not-return-status-information-for-a-form-rendered-in-the-same-component*/}
0 commit comments