-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create prefetch-data-for-remix-fetcher-usage.md
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
content/tutorials/prefetch-data-for-remix-fetcher-usage.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#@remix-run/react@2.0.0 | ||
|
||
# Prefetch data for Remix Fetcher usage | ||
|
||
If you're using Remix, you can ask it to prefetch the data of a new route using `<Link prefetch`> prop, but if you need to use `fetcher.load` or `fetcher.submit` to load some data, you can't use the Link. | ||
|
||
To be able to prefetch them you can do the same thing Link component does, render a `<PrefetchPageLinks>` component. | ||
|
||
```tsx | ||
let fetcher = useFetcher<typeof resourceLoader>(); | ||
|
||
return ( | ||
<> | ||
<PrefetchPageLinks page="/resource" /> | ||
<button type="button" onClick={() => fetcher.load("/resource")}> | ||
Load Data | ||
</button> | ||
{fetcher.data && <DisplayData data={fetcher.data} />} | ||
</> | ||
); | ||
``` | ||
|
||
Now when the HTML tag is rendered it will start prefetching the data, and once the user finally clicks the link it will be ready. | ||
|
||
If you want to see a demo app, here's the code https://github.com/sergiodxa/remix-demo-prefetch-fetcher. |