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 {
7 states,
8 onFetch,
9 }: {
10 states: StatelessRef<Array<StatusResult<string>>>
11 onFetch: () => void
12 } = $props()
13β
14 const query = createQuery(() => ({
15 queryKey: ['test'],
16 queryFn: async () => {
17 await sleep(10)
18 onFetch()
19 return 'fetched'
20 },
21 staleTime: Infinity,
22 }))
23β
24 $effect(() => {
25 const snapshot = $state.snapshot(query)
26 states.current.push(snapshot)
27 })
28</script>
29β
30<div>data: {query.data ?? 'null'}</div>
31<div>fetchStatus: {query.fetchStatus}</div>