forked from TanStack/query
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFreshData.svelte
More file actions
32 lines (28 loc) · 765 Bytes
/
FreshData.svelte
File metadata and controls
32 lines (28 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<script lang="ts">
import { createQuery } from '@tanstack/svelte-query'
import { sleep } from '@tanstack/query-test-utils'
import type { StatelessRef, StatusResult } from '../utils.svelte.js'
let {
states,
onFetch,
}: {
states: StatelessRef<Array<StatusResult<string>>>
onFetch: () => void
} = $props()
const query = createQuery(() => ({
queryKey: ['test'],
queryFn: async () => {
await sleep(10)
onFetch()
return 'fetched'
},
staleTime: Infinity,
}))
$effect(() => {
// svelte-ignore state_snapshot_uncloneable
const snapshot = $state.snapshot(query)
states.current.push(snapshot)
})
</script>
<div>data: {query.data ?? 'null'}</div>
<div>fetchStatus: {query.fetchStatus}</div>