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

+page.svelte

38 lines1.1 KB

1<script lang="ts">
2 import { resolve } from '$app/paths'
3 import { moviesQueries } from '$lib/services/movies/queries'
4 import { createQuery } from '@tanstack/svelte-query'
5​
6 const moviesQuery = createQuery(() => moviesQueries.list())
7</script>
8​
9{#if moviesQuery.isLoading}
10 Loading...
11{:else if moviesQuery.data}
12 <div>
13 <h1>Movies</h1>
14 <p>
15 Try to mock offline behavior with the button in the devtools. You can
16 navigate around as long as there is already data in the cache. You'll get
17 a refetch as soon as you go online again.
18 </p>
19 <ul>
20 {#each moviesQuery.data.movies as movie (movie.id)}
21 <li>
22 <a href={resolve('/[movieId]', { movieId: movie.id })}>
23 {movie.title}
24 </a>
25 </li>
26 {/each}
27 </ul>
28 <div>
29 Updated at: {new Date(moviesQuery.data.ts).toLocaleTimeString()}
30 </div>
31 <div>{moviesQuery.isFetching ? 'fetching...' : ''}</div>
32 </div>
33{:else if moviesQuery.isError}
34 <div>
35 <h1>Couldn't load movies!</h1>
36 <div>{moviesQuery.error.message}</div>
37 </div>
38{/if}