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 { StatelessRef, StatusResult } from '../utils.svelte.js'
5β
6 let { states }: { states: StatelessRef<Array<StatusResult<string>>> } =
7 $props()
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 $effect(() => {
23 // svelte-ignore state_snapshot_uncloneable
24 const snapshot = $state.snapshot(query)
25 states.current.push(snapshot)
26 })
27</script>
28β
29<div>{query.data}</div>
30<div>fetchStatus: {query.fetchStatus}</div>