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

index.tsx

51 lines1.5 KB

1import { For, Match, Show, Switch } from 'solid-js'
2import { Link, createFileRoute } from '@tanstack/solid-router'
3import { useQuery } from '@tanstack/solid-query'
4import { moviesQueries } from '../services/movies/queries'
5​
6export const Route = createFileRoute('/')({
7 component: List,
8})
9​
10function List() {
11 const moviesQuery = useQuery(() => moviesQueries.list())
12​
13 return (
14 <Switch>
15 <Match when={moviesQuery.isLoading}>Loading...</Match>
16 <Match when={moviesQuery.data}>
17 <div>
18 <h1>Movies</h1>
19 <p>
20 Try to mock offline behavior with the button in the devtools. You
21 can navigate around as long as there is already data in the cache.
22 You'll get a refetch as soon as you go online again.
23 </p>
24 <ul>
25 <For each={moviesQuery.data!.movies}>
26 {(movie) => (
27 <li>
28 <Link to="/$movieId" params={{ movieId: movie.id }}>
29 {movie.title}
30 </Link>
31 </li>
32 )}
33 </For>
34 </ul>
35 <div>
36 Updated at: {new Date(moviesQuery.data!.ts).toLocaleTimeString()}
37 </div>
38 <Show when={moviesQuery.isFetching}>
39 <div>fetching...</div>
40 </Show>
41 </div>
42 </Match>
43 <Match when={moviesQuery.isError}>
44 <div>
45 <h1>Couldn't load movies!</h1>
46 <div>{moviesQuery.error?.message}</div>
47 </div>
48 </Match>
49 </Switch>
50 )