Skip to content

Commit 6eaf2d6

Browse files
committed
pr feedback
1 parent 42a5853 commit 6eaf2d6

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

decisions/0003-infer-types-for-useloaderdata-and-useactiondata-from-loader-and-action-via-generics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Date: 2022-07-11
44

5-
Status: Superceded by [#0012](./0012-type-inference.md)
5+
Status: Superseded by [#0012](./0012-type-inference.md)
66

77
## Context
88

decisions/0012-type-inference.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Date: 2024-09-20
44

55
Status: accepted
66

7-
Supercedes [#0003](./0003-infer-types-for-useloaderdata-and-useactiondata-from-loader-and-action-via-generics.md)
7+
Supersedes [#0003](./0003-infer-types-for-useloaderdata-and-useactiondata-from-loader-and-action-via-generics.md)
88

99
## Context
1010

@@ -53,11 +53,16 @@ There are three major aspects to typesafety in a framework like React Router:
5353
However, it still requires you to add `typeof loader` every time.
5454

5555
Not only that, but complex routes get very tricky to type correctly.
56+
For example, `clientLoader`s don't run during the initial SSR render, but you can force the `clientLoader` data to always be present in your route component if you set `clientLoader.hydrate = true` _and_ provide a `HydrateFallback`.
57+
Here are a couple cases that trip up most users:
5658

57-
> What if the route also has a `clientLoader`?
58-
> Did you remember to change the generic to `typeof clientLoader`?
59-
> But in the initial SSR render, the `clientLoader` doesn't run, so really you'd need `typeof loader | typeof clientLoader`.
60-
> Unless you also set `clientLoader.hydrate = true` _AND_ provided a `HydrateFallback`. Then `clientLoader` always runs so you'd want just `typeof clientLoader`
59+
| `loader` | `clientLoader` | `clientLoader.hydrate` | `HydrateFallback` | Generic for `useLoaderData` |
60+
| -------- | -------------- | ---------------------- | ----------------- | -------------------------------------- |
61+
||| `false` || `typeof loader` |
62+
||| `false` || `typeof clientLoader \| undefined` |
63+
||| `false` || `typeof loader \| typeof clientLoader` |
64+
||| `true` || `typeof loader \| typeof clientLoader` |
65+
||| `true` || `typeof clientLoader` |
6166

6267
The generic for `useLoaderData` starts to feel a lot like doing your taxes: there's only one right answer, Remix knows what it is, but you're going to get quizzed on it anyway.
6368

@@ -151,7 +156,7 @@ For example:
151156
- product.tsx
152157
```
153158

154-
The path within `.react-router/types` purposefully mirrors the path to the correspond route module.
159+
The path within `.react-router/types` purposefully mirrors the path to the corresponding route module.
155160
By setting things up like this, we can use `tsconfig.json`'s [rootDirs](https://www.typescriptlang.org/tsconfig/#rootDirs) option to let you conveniently import from the typegen file as if it was a sibling:
156161

157162
```ts

0 commit comments

Comments
 (0)