Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

RestoreCache.svelte

21 lines587 Bytes

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: () => sleep(10).then(() => 'fetched'),
12 }))
13​
14 $effect(() => {
15 const snapshot = $state.snapshot(query)
16 states.current.push(snapshot)
17 })
18</script>
19​
20<div>{query.data}</div>
21<div>fetchStatus: {query.fetchStatus}</div>