Download react-query/examples/svelte/basic/src/lib/Post.svelte from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 704 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/svelte/basic/src/lib/Post.svelte
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/svelte/basic/src/lib/Post.svelte
-
curl -L -o Post.svelte https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/svelte/basic/src/lib/Post.svelte
704 Bytes
| <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> | |