Skip to content

Commit 587bf55

Browse files
tentaShiratorikodiakhq[bot]LadyBluenotes
authored
Replace load with preload (#967)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Sarah <gerrardsarah@gmail.com>
1 parent 8b6ece2 commit 587bf55

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

src/i18n/dictionaries/en/ui.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default {
2828
"main.nav.section.solid.router": "Solid-Router",
2929
"main.nav.section.solid.router.components": "Components",
3030
"main.nav.section.solid.router.data.apis": "Data APIs",
31-
"main.nav.section.solid.router.load.functions": "Load Functions",
31+
"main.nav.section.solid.router.preload.functions": "Preload Functions",
3232
"main.nav.section.solid.router.primitives": "Primitives",
3333
"main.nav.no.routes": "No routes found",
3434

src/routes/guides/routing-and-navigation.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ function preloadUser({ params, location }) {
463463
The preload function is then passed in the `<Route>` definition:
464464

465465
```jsx
466-
<Route path="/users/:id" component={User} preload={loadUser} />
466+
<Route path="/users/:id" component={User} preload={preloadUser} />
467467
```
468468

469469
---

src/routes/solid-router/guides/migration.mdx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Removing the second way to define route components to reduce confusion and edge
2626
## `data` functions & `useRouteData`
2727

2828
`data` functions & `useRouteData` have been replaced by a load mechanism.
29-
This allows link hover preloads, since the load function can be run as much as wanted without worrying about reactivity.
29+
This allows link hover preloads, since the preload function can be run as much as wanted without worrying about reactivity.
3030

3131
This supports deduping/cache APIs which give more control over how things are cached.
3232
It also addresses TypeScript issues with getting the right types in the Component without `typeof` checks.
@@ -35,32 +35,35 @@ That being said the old pattern can be reproduced by turning off preloads at the
3535

3636
```js
3737
import { lazy } from "solid-js";
38-
import { Route } from "@solidjs/router";
38+
import { Router, Route } from "@solidjs/router";
3939

4040
const User = lazy(() => import("./pages/users/[id].js"));
4141

42-
// load function
43-
function loadUser({ params, location }) {
42+
// preload function
43+
function preloadUser({ params, location }) {
4444
const [user] = createResource(() => params.id, fetchUser);
4545
return user;
4646
}
4747

4848
// Pass it in the route definition
4949
<Router preload={false}>
50-
<Route path="/users/:id" component={User} load={loadUser} />
50+
<Route path="/users/:id" component={User} preload={preloadUser} />
5151
</Router>;
5252
```
5353

5454
And then in your component taking the page props and putting them in a Context.
5555

5656
```js
57+
import { createContext, useContext } from "solid-js";
58+
59+
const UserContext = createContext();
60+
5761
function User(props) {
58-
<UserContext.Provider value={props.data}>
59-
{/* my component content */}
62+
<UserContext.Provider value={props.data()}>
63+
{/* my component content that includes <UserDetails /> in any depth */}
6064
</UserContext.Provider>;
6165
}
6266

63-
// Somewhere else
6467
function UserDetails() {
6568
const user = useContext(UserContext);
6669
// render stuff

src/routes/solid-router/rendering-modes/ssr.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ import { Router } from "@solidjs/router";
1414
<Router url={isServer ? req.url : ""} />;
1515
```
1616

17-
Solid Router also provides a way to define a `load` function that loads parallel to the routes [render-as-you-fetch](https://epicreact.dev/render-as-you-fetch/).
17+
Solid Router also provides a way to define a `preload` function that loads parallel to the routes [render-as-you-fetch](https://epicreact.dev/render-as-you-fetch/).

0 commit comments

Comments
 (0)