Open History to see the last commit
1<script lang="ts">
2 import { QueryClient } from '@tanstack/query-core'
3 import { derived, writable } from 'svelte/store'
4 import { createQuery } from '../../src/index.js'
5 import { sleep } from '../utils.js'
6 import type { QueryObserverResult } from '@tanstack/query-core'
7 import type { Writable } from 'svelte/store'
8β
9 export let states: Writable<Array<QueryObserverResult>>
10β
11 const queryClient = new QueryClient()
12 const count = writable(0)
13β
14 const options = derived(count, ($count) => ({
15 queryKey: ['test', $count],
16 queryFn: async () => {
17 await sleep(5)
18 return $count
19 },
20 enabled: $count === 0,
21 }))
22β
23 const query = createQuery(options, queryClient)
24β
25 $: states.update((prev) => [...prev, $query])
26</script>
27β
28<button on:click={() => ($count += 1)}>Increment</button>
29β
30<div>Data: {$query.data ?? 'undefined'}</div>
31<div>Count: {$count}</div>