Course contentsShow
← React
Lesson 1495 of 2,39637. React 19 and BeyondFree lesson

Accessing Form Data in useFormStatus

Extract submitted form data and method information from useFormStatus to display context-aware loading messages.

Accessing Form Data in useFormStatus

You'll learn how to extract submitted form data and HTTP method from useFormStatus to create context-aware loading states.

The Context-Aware Loading Challenge

When you disabled a submit button with pending, it showed the same "Submitting..." text for every action. But what if you have multiple buttons in one form, or want to display what is being submitted? The useFormStatus hook exposes the actual form data and HTTP method that triggered the pending state, letting you craft intelligent loading messages.

Reading FormData from useFormStatus

The hook returns a data property containing the FormData object being submitted:

function SubmitButton() {
  const { pending, data, method } = useFormStatus();
  
  // data is the FormData being submitted
  const action = data?.get('action'); // read specific fields
  
  if (pending) {
    return <button disabled>Processing {action}...</button>;
  }
  
  return <button type="submit">Submit</button>;
}

Practical Example: Multi-Action Forms

function UserForm() {
  return (
    <form action={handleUser}>
      <input name="username" />
      
      <button name="action" value="save">
        Save
      </button>
      <button name="action" value="delete">
        Delete
      </button>
      
      <SubmitStatus />
    </form>
  );
}

function SubmitStatus() {
  const { pending, data } = useFormStatus();
  
  if (!pending) return null;
  
  const action = data.get('action');
  return <p>Currently {action === 'delete' ? 'deleting' : 'saving'}...</p>;
}

The data object lets you inspect exactly what was submitted. The method property tells you if it's "GET", "POST", etc.

Key Takeaway: useFormStatus exposes data (FormData) and method (HTTP method) so you can display specific, context-aware feedback based on what the user actually submitted, not just generic "loading" states.