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

list.tsx

45 lines1.4 KB

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