Skip to content

Commit

Permalink
docs: update actions to use ActionArgs (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey committed Jan 14, 2023
1 parent be566d3 commit 4c7dfc9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ In Remix, your submit your forms to an `action` which receives the `FormData`. I
```js
import { validateServerFormData } from "remix-validity-state";

export async function action({ request }) {
export async function action({ request }: ActionArgs) {
const formData = await request.formData();
const serverFormInfo = await validateServerFormData(
formData,
Expand All @@ -162,7 +162,7 @@ When we validate on the server, we may get errors back that we didn't catch duri
import { Field, FormContextProvider } from "remix-validity-state";

export default function MyRemixRouteComponent() {
let actionData = useActionData();
let actionData = useActionData<typeof action>();
return (
<FormContextProvider
value={{
Expand Down
10 changes: 5 additions & 5 deletions demo-app/app/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Form, useActionData } from "@remix-run/react";
import type { ActionFunction } from "@remix-run/server-runtime";
import { json, redirect } from "@remix-run/server-runtime";
import type { ActionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import * as React from "react";
import type {
ErrorMessage,
Expand Down Expand Up @@ -81,7 +81,7 @@ type ActionData = {
serverFormInfo: ServerFormInfo<typeof formDefinition>;
};

export const action: ActionFunction = async ({ request }) => {
export const action = async ({ request }: ActionArgs) => {
const formData = await request.formData();

// Validate server-side using the same validations specified in the <input>
Expand All @@ -92,7 +92,7 @@ export const action: ActionFunction = async ({ request }) => {
const serverFormInfo = await validateServerFormData(formData, formDefinition);

if (!serverFormInfo.valid) {
return json<ActionData>({ serverFormInfo });
return json({ serverFormInfo });
}
return redirect("/");
};
Expand All @@ -119,7 +119,7 @@ function EmailAddress() {
}

export default function Index() {
let actionData = useActionData() as ActionData;
let actionData = useActionData<typeof action>();

let formRef = React.useRef<HTMLFormElement>(null);

Expand Down

0 comments on commit 4c7dfc9

Please sign in to comment.