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

Post.svelte

32 lines715 Bytes

1<script lang="ts">
2 import { createQuery } from '@tanstack/svelte-query'
3 import { resolve } from '$app/paths'
4 import { postsQueries } from './services/posts/queries'
5​
6 type Props = {
7 postId: number
8 }
9​
10 let { postId }: Props = $props()
11​
12 const post = createQuery(() => postsQueries.detail(postId))
13</script>
14​
15<div>
16 <div>
17 <a class="button" href={resolve('/')}> Back </a>
18 </div>
19 {#if post.isPending}
20 <span>Loading...</span>
21 {/if}
22 {#if post.error}
23 <span>Error: {post.error.message}</span>
24 {/if}
25 {#if post.isSuccess}
26 <h1>{post.data.title}</h1>
27 <div>
28 <p>{post.data.body}</p>
29 </div>
30 <div>{post.isFetching ? 'Background Updating...' : ' '}</div>
31 {/if}
32</div>