Skip to content

Latest commit

 

History

History
52 lines (39 loc) · 1.16 KB

use-action-data.md

File metadata and controls

52 lines (39 loc) · 1.16 KB
title toc
useActionData
false

useActionData

Returns the serialized data from the most recent route action or undefined if there isn't one.

import type { ActionFunctionArgs } from "@remix-run/node"; // or cloudflare/deno
import { json } from "@remix-run/node"; // or cloudflare/deno
import { Form, useActionData } from "@remix-run/react";

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

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

Additional Resources

Guides

Related API

Discussions