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

IsRestoringExample.svelte

30 lines773 Bytes

1<script lang="ts">
2 import type { QueryClient } from '@tanstack/query-core'
3 import { queryKey } from '@tanstack/query-test-utils'
4 import {
5 setIsRestoringContext,
6 setQueryClientContext,
7 } from '../../src/context.js'
8 import { createQuery } from '../../src/index.js'
9​
10 type Props = {
11 queryClient: QueryClient
12 queryFn: () => Promise<string>
13 }
14​
15 let { queryClient, queryFn }: Props = $props()
16​
17 setQueryClientContext(queryClient)
18 setIsRestoringContext({ current: true })
19​
20 const query = createQuery(() => ({
21 queryKey: queryKey(),
22 queryFn,
23 }))
24</script>
25​
26<div>
27 <div data-testid="status">{query.status}</div>
28 <div data-testid="fetchStatus">{query.fetchStatus}</div>
29 <div data-testid="data">{query.data ?? 'undefined'}</div>
30</div>