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