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

App.svelte

33 lines1.0 KB

1<script lang="ts">
2 import { QueryClient, QueryClientProvider } from '@tanstack/svelte-query'
3 import { SvelteQueryDevtools } from '@tanstack/svelte-query-devtools'
4 import Post from './lib/Post.svelte'
5 import Posts from './lib/Posts.svelte'
6​
7 const queryClient = new QueryClient()
8​
9 let postId = $state<string | null>(null)
10​
11 const setPostId = (id: string | null) => {
12 postId = id
13 }
14</script>
15​
16<QueryClientProvider client={queryClient}>
17 <p>
18 As you visit the posts below, you will notice them in a loading state the
19 first time you load them. However, after you return to this list and click
20 on any posts you have already visited again, you will see them load
21 instantly and background refresh right before your eyes!
22 <strong>
23 (You may need to throttle your network speed to simulate longer loading
24 sequences)
25 </strong>
26 </p>
27 {#if postId !== null}
28 <Post {postId} {setPostId} />
29 {:else}
30 <Posts {setPostId} />
31 {/if}
32 <SvelteQueryDevtools initialIsOpen />
33</QueryClientProvider>