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

Simple.svelte

41 lines970 Bytes

1<script lang="ts">
2 import { createQuery } from '@tanstack/svelte-query'
3​
4 type Repo = {
5 full_name: string
6 description: string
7 subscribers_count: number
8 stargazers_count: number
9 forks_count: number
10 }
11​
12 const query = createQuery<Repo>({
13 queryKey: ['repoData'],
14 queryFn: async () =>
15 await fetch('https://api.github.com/repos/TanStack/query').then((r) =>
16 r.json(),
17 ),
18 })
19</script>
20​
21<h1>Simple</h1>
22<div class="my-4">
23 <div>
24 {#if $query.isPending}
25 Loading...
26 {/if}
27 {#if $query.error}
28 An error has occurred:
29 {$query.error.message}
30 {/if}
31 {#if $query.isSuccess}
32 <div>
33 <h1>{$query.data.full_name}</h1>
34 <p>{$query.data.description}</p>
35 <strong>πŸ‘€ {$query.data.subscribers_count}</strong>{' '}
36 <strong>✨ {$query.data.stargazers_count}</strong>{' '}
37 <strong>🍴 {$query.data.forks_count}</strong>
38 </div>
39 {/if}
40 </div>
41</div>