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

RestoreCache.svelte

22 lines635 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 // svelte-ignore state_snapshot_uncloneable
16 const snapshot = $state.snapshot(query)
17 states.current.push(snapshot)
18 })
19</script>
20​
21<div>{query.data}</div>
22<div>fetchStatus: {query.fetchStatus}</div>