Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

prefetch.tsx

40 lines1.3 KB

1import { Title } from '@solidjs/meta'
2import { noop, useQueryClient } from '@tanstack/solid-query'
3import { UserInfo, userInfoQueryOpts } from '~/components/user-info'
4​
5export const route = {
6 preload: () => {
7 const queryClient = useQueryClient()
8 // Prefetching the user info and caching it for 15 seconds.
9 queryClient
10 .query(userInfoQueryOpts({ sleep: 500, gcTime: 15000 }))
11 .catch(noop)
12 },
14​
15export default function Prefetch() {
16 return (
17 <main>
18 <Title>Solid Query - Prefetch</Title>
19​
20 <h1>Solid Query - Prefetch Example</h1>
21​
22 <div class="description">
23 <p>
24 SolidStart now supports link prefetching. This means that when a user
25 hovers over a link, the browser can prefetch the data for that page
26 before the user even clicks on the link. This can make navigating
27 around your app feel much faster.
28 </p>
29 <p>
30 To see this in action, go to the home page and reload the page. Then
31 hover over the "Prefetch" link in the navigation. You should see the
32 user data prefetch in the background and in the devtools. When you
33 click on the link, the page should load instantly.
34 </p>
35 </div>
36​
37 <UserInfo sleep={500} />
38 </main>
39 )