React Router API Reference
    Preparing search index...

    Function data

    • Create "responses" that contain headers/status without forcing serialization into an actual Response

      Type Parameters

      • D

      Parameters

      • data: D

        The data to be included in the response.

      • Optionalinit: number | ResponseInit

        The status code or a ResponseInit object to be included in the response.

      Returns UNSAFE_DataWithResponseInit<D>

      A DataWithResponseInit instance containing the data and response init.

      import { data } from "react-router";

      export async function action({ request }: Route.ActionArgs) {
      let formData = await request.formData();
      let item = await createItem(formData);
      return data(item, {
      headers: { "X-Custom-Header": "value" }
      status: 201,
      });
      }

      @public

      framework

      data