--- title: useFormStatus --- `useFormStatus` is a Hook that gives you status information of the last form submission. ```js const { pending, data, method, action } = useFormStatus(); ``` --- ## Reference {/*reference*/} ### `useFormStatus()` {/*use-form-status*/} The `useFormStatus` Hook provides status information of the last form submission. ```js {5},[[1, 6, "status.pending"]] import { useFormStatus } from "react-dom"; import action from './actions'; function Submit() { const status = useFormStatus(); return } export default function App() { return (
); } ``` To get status information, the `Submit` component must be rendered within a `
`. The Hook returns information like the `pending` property which tells you if the form is actively submitting. In the above example, `Submit` uses this information to disable ` ); } function Form({ action }) { return ( ); } export default function App() { return
; } ``` ```js src/actions.js hidden export async function submitForm(query) { await new Promise((res) => setTimeout(res, 1000)); } ``` ##### `useFormStatus` will not return status information for a `` rendered in the same component. {/*useformstatus-will-not-return-status-information-for-a-form-rendered-in-the-same-component*/} The `useFormStatus` Hook only returns status information for a parent `` and not for any `` rendered in the same component calling the Hook, or child components. ```js function Form() { // 🚩 `pending` will never be true // useFormStatus does not track the form rendered in this component const { pending } = useFormStatus(); return ; } ``` Instead call `useFormStatus` from inside a component that is located inside `
`. ```js function Submit() { // ✅ `pending` will be derived from the form that wraps the Submit component const { pending } = useFormStatus(); return ; } function Form() { // This is the `useFormStatus` tracks return ( ); } ```
### Read the form data being submitted {/*read-form-data-being-submitted*/} You can use the `data` property of the status information returned from `useFormStatus` to display what data is being submitted by the user. Here, we have a form where users can request a username. We can use `useFormStatus` to display a temporary status message confirming what username they have requested. ```js src/UsernameForm.js active import {useState, useMemo, useRef} from 'react'; import {useFormStatus} from 'react-dom'; export default function UsernameForm() { const {pending, data} = useFormStatus(); return (

Request a Username:


{data ? `Requesting ${data?.get("username")}...`: ''}

); } ``` ```js src/App.js import UsernameForm from './UsernameForm'; import { submitForm } from "./actions.js"; import {useRef} from 'react'; export default function App() { const ref = useRef(null); return (
{ await submitForm(formData); ref.current.reset(); }}> ); } ``` ```js src/actions.js hidden export async function submitForm(query) { await new Promise((res) => setTimeout(res, 2000)); } ``` ```css p { height: 14px; padding: 0; margin: 2px 0 0 0 ; font-size: 14px } button { margin-left: 2px; } ```
--- ## Troubleshooting {/*troubleshooting*/} ### `status.pending` is never `true` {/*pending-is-never-true*/} `useFormStatus` will only return status information for a parent `
`. If the component that calls `useFormStatus` is not nested in a ``, `status.pending` will always return `false`. Verify `useFormStatus` is called in a component that is a child of a `` element. `useFormStatus` will not track the status of a `` rendered in the same component. See [Pitfall](#useformstatus-will-not-return-status-information-for-a-form-rendered-in-the-same-component) for more details. --- ## Sitemap [Overview of all docs pages](/llms.txt)