diff --git a/docs/api/conventions.md b/docs/api/conventions.md index b8686a667e2..60d2eacc938 100644 --- a/docs/api/conventions.md +++ b/docs/api/conventions.md @@ -265,21 +265,17 @@ For example: `app/routes/blog/$postId.tsx` will match the following URLs: On each of these pages, the dynamic segment of the URL path is the value of the parameter. There can be multiple parameters active at any time (as in `/dashboard/:client/invoices/:invoiceId` [view example app][view-example-app]) and all parameters can be accessed within components via [`useParams`][use-params] and within loaders/actions via the argument's [`params`][params] property: ```tsx filename=app/routes/blog/$postId.tsx -import { useParams } from "@remix-run/react"; import type { - LoaderFunction, - ActionFunction, + ActionArgs, + LoaderArgs, } from "@remix-run/node"; // or cloudflare/deno +import { useParams } from "@remix-run/react"; -export const loader: LoaderFunction = async ({ - params, -}) => { +export const loader = async ({ params }: LoaderArgs) => { console.log(params.postId); }; -export const action: ActionFunction = async ({ - params, -}) => { +export const action = async ({ params }: ActionArgs) => { console.log(params.postId); }; @@ -428,21 +424,17 @@ Files that are named `$.tsx` are called "splat" (or "catch-all") routes. These r Similar to dynamic route parameters, you can access the value of the matched path on the splat route's `params` with the `"*"` key. ```tsx filename=app/routes/$.tsx -import { useParams } from "@remix-run/react"; import type { - LoaderFunction, - ActionFunction, + ActionArgs, + LoaderArgs, } from "@remix-run/node"; // or cloudflare/deno +import { useParams } from "@remix-run/react"; -export const loader: LoaderFunction = async ({ - params, -}) => { +export const loader = async ({ params }: LoaderArgs) => { console.log(params["*"]); }; -export const action: ActionFunction = async ({ - params, -}) => { +export const action = async ({ params }: ActionArgs) => { console.log(params["*"]); }; @@ -554,7 +546,7 @@ export default function SomeRouteComponent() { Each route can define a "loader" function that will be called on the server before rendering to provide data to the route. You may think of this as a "GET" request handler in that you should not be reading the body of the request; that is the job of an [`action`][action]. -```js +```tsx import { json } from "@remix-run/node"; // or cloudflare/deno export const loader = async () => { @@ -564,16 +556,6 @@ export const loader = async () => { }; ``` -```ts -// Typescript -import { json } from "@remix-run/node"; // or cloudflare/deno -import type { LoaderFunction } from "@remix-run/node"; // or cloudflare/deno - -export const loader: LoaderFunction = async () => { - return json({ ok: true }); -}; -``` - This function is only ever run on the server. On the initial server render it will provide data to the HTML document. On navigations in the browser, Remix will call the function via [`fetch`][fetch]. This means you can talk directly to your database, use server only API secrets, etc. Any code that isn't used to render the UI will be removed from the browser bundle. Using the database ORM Prisma as an example: @@ -589,7 +571,7 @@ export const loader = async () => { }; export default function Users() { - const data = useLoaderData(); + const data = useLoaderData(); return (