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