useActionData

useActionData

Summary

Reference Documentation ↗

Returns the action data from the most recent POST navigation form submission or undefined if there hasn't been one.

import { Form, useActionData } from "react-router";

export async function action({ request }) {
  const body = await request.formData();
  const name = body.get("visitorsName");
  return { message: `Hello, ${name}` };
}

export default function Invoices() {
  const data = useActionData();
  return (
    <Form method="post">
      <input type="text" name="visitorsName" />
      {data ? data.message : "Waiting..."}
    </Form>
  );
}

Signature

useActionData(): undefined
Docs and examples CC 4.0