Skip to content

Commit a1bed3e

Browse files
committed
docs: tutorial tweaks
1 parent e610a24 commit a1bed3e

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

docs/getting-started/tutorial.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ export default function Contact() {
321321
}
322322

323323
function Favorite({ contact }) {
324+
// yes, this is a `let` for later
324325
let favorite = contact.favorite;
325326
return (
326327
<Form method="post">
@@ -586,7 +587,7 @@ We'll create new contacts by exporting an `action` in our root route, wiring it
586587

587588
👉 **Create the action and change `<form>` to `<Form>`**
588589

589-
```jsx filename=src/routes/root.jsx lines=[7,5,9-11,22-24]
590+
```jsx filename=src/routes/root.jsx lines=[5,7,9-11,22-24]
590591
import {
591592
Outlet,
592593
Link,
@@ -744,6 +745,11 @@ Nothing we haven't seen before, feel free to copy/paste:
744745

745746
```jsx filename=src/routes/edit.jsx
746747
import { Form, useLoaderData } from "react-router-dom";
748+
import { getContact } from "../contacts";
749+
750+
export function loader({ params }) {
751+
return getContact(params.contactId);
752+
}
747753

748754
export default function Edit() {
749755
const contact = useLoaderData();
@@ -837,10 +843,6 @@ ReactDOM.createRoot(document.getElementById("root")).render(
837843

838844
We want it to be rendered in the root route's outlet, so we made it a sibling to the existing child route.
839845

840-
> 🤨 Is that `loader={contactLoader}` for both route's?
841-
842-
Yep. Both routes need the contact, and both use the same param name (`:contactId`), so they can share the same loader. Kinda cool.
843-
844846
Alright, clicking the "Edit" button gives us this new UI:
845847

846848
<img class="tutorial" loading="lazy" src="/_docs/tutorial/11.webp" />
@@ -1086,6 +1088,8 @@ In our case, we add a `"loading"` class to the main part of the app if we're not
10861088

10871089
<img class="tutorial" loading="lazy" src="/_docs/tutorial/16.webp" />
10881090

1091+
Note that our data model (`src/contact.js`) has a clientside cache, so navigating to the same contact is fast the second time. This behavior is _not_ React Router, it will re-load data for changing routes no matter if you've been there before or not. It does, however, avoid calling the loaders for _unchanging_ routes (like the list) during a navigation.
1092+
10891093
## Deleting Records
10901094

10911095
If we review code in the contact route, we can find the delete button looks like this:
@@ -1372,7 +1376,7 @@ Let's use client side routing to submit this form and filter the list in our exi
13721376

13731377
👉 **Filter the list if there are URLSearchParams**
13741378

1375-
```jsx filename=src/routes/root.jsx lines=[2-4]
1379+
```jsx filename=src/routes/root.jsx lines=[1,2-4]
13761380
export async function loader({ request }) {
13771381
const url = new URL(request.url);
13781382
const q = url.searchParams.get("q");
@@ -1734,7 +1738,7 @@ Pretty simple. Pull the form data off the request and send it to the data model.
17341738

17351739
👉 **Configure the route's new action**
17361740

1737-
```jsx filename=src/main.jsx lines=[5, 21]
1741+
```jsx filename=src/main.jsx lines=[]
17381742
// existing code
17391743

17401744
import Contact, {

0 commit comments

Comments
 (0)