You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -53,11 +53,16 @@ There are three major aspects to typesafety in a framework like React Router:
53
53
However, it still requires you to add `typeof loader` every time.
54
54
55
55
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:
56
58
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`|
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.
63
68
@@ -151,7 +156,7 @@ For example:
151
156
- product.tsx
152
157
```
153
158
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.
155
160
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:
0 commit comments