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

TwoQueries.svelte

34 lines1.1 KB

1<script lang="ts">
2 import { onDestroy, onMount } from 'svelte'
3 import { createQuery, setQueryClientContext } from '../../src/index.js'
4 import type { QueryClient } from '@tanstack/query-core'
5 import type { Accessor, CreateQueryOptions } from '../../src/index.js'
6​
7 type Props = {
8 queryClient: QueryClient
9 options1: Accessor<CreateQueryOptions>
10 options2: Accessor<CreateQueryOptions>
11 }
12​
13 let { queryClient, options1, options2 }: Props = $props()
14​
15 setQueryClientContext(queryClient)
16​
17 onMount(() => queryClient.mount())
18 onDestroy(() => queryClient.unmount())
19​
20 const query1 = createQuery(options1)
21 const query2 = createQuery(options2)
22</script>
23​
24<button onclick={() => query1.refetch()}>refetch1</button>
25​
26<div data-testid="status1">{query1.status}</div>
27<div data-testid="fetchStatus1">{query1.fetchStatus}</div>
28<div data-testid="data1">{query1.data ?? 'undefined'}</div>
29<div data-testid="isStale1">{query1.isStale}</div>
30​
31<div data-testid="status2">{query2.status}</div>
32<div data-testid="fetchStatus2">{query2.fetchStatus}</div>
33<div data-testid="data2">{query2.data ?? 'undefined'}</div>
34<div data-testid="isStale2">{query2.isStale}</div>