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

prefetch.tsx

41 lines1.3 KB

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