Open History to see the last commit
1<script lang="ts">
2 import { createQuery } from '@tanstack/svelte-query'
3 import { getPostById } from './data'
4 import type { Post } from './types'
5β
6 export let postId: number
7β
8 const post = createQuery<Post>({
9 queryKey: ['post', postId],
10 queryFn: () => getPostById(postId),
11 })
12</script>
13β
14<div>
15 <div>
16 <a class="button" href="/"> Back </a>
17 </div>
18 {#if !postId || $post.isPending}
19 <span>Loading...</span>
20 {/if}
21 {#if $post.error}
22 <span>Error: {$post.error.message}</span>
23 {/if}
24 {#if $post.isSuccess}
25 <h1>{$post.data.title}</h1>
26 <div>
27 <p>{$post.data.body}</p>
28 </div>
29 <div>{$post.isFetching ? 'Background Updating...' : ' '}</div>
30 {/if}
31</div>