Open History to see the last commit
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 const response = await fetch(
16 'https://api.github.com/repos/TanStack/query',
17 )
18 if (!response.ok) throw new Error('Failed to fetch repo data')
19 return await response.json()
20 },
21 }))
22</script>
23β
24<h1>Simple</h1>
25<div class="my-4">
26 <div>
27 {#if query.isPending}
28 Loading...
29 {/if}
30 {#if query.error}
31 An error has occurred:
32 {query.error.message}
33 {/if}
34 {#if query.isSuccess}
35 <div>
36 <h1>{query.data.full_name}</h1>
37 <p>{query.data.description}</p>
38 <strong>π {query.data.subscribers_count}</strong>
39 <strong>β¨ {query.data.stargazers_count}</strong>
40 <strong>π΄ {query.data.forks_count}</strong>
41 </div>
42 {/if}
43 </div>
44</div>