Open History to see the last commit
1<script lang="ts">
2 import { createQuery } from '@tanstack/svelte-query'
3 import { sleep } from '@tanstack/query-test-utils'
4 import type { Writable } from 'svelte/store'
5 import type { StatusResult } from '../utils.js'
6β
7 export let states: Writable<Array<StatusResult<string>>>
8β
9 const query = createQuery({
10 queryKey: ['test'],
11 queryFn: async () => {
12 await sleep(5)
13 return 'fetched'
14 },
15β
16 initialData: 'initial',
17 // make sure that initial data is older than the hydration data
18 // otherwise initialData would be newer and takes precedence
19 initialDataUpdatedAt: 1,
20 })
21β
22 $: states.update((prev) => [...prev, $query])
23</script>
24β
25<div>{$query.data}</div>
26<div>fetchStatus: {$query.fetchStatus}</div>