File size: 910 Bytes
1e92f2d |
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 |
<script lang="ts">
import { QueryClient } from '@tanstack/query-core'
import { derived, writable } from 'svelte/store'
import { createQuery } from '../../src/index.js'
import { sleep } from '@tanstack/query-test-utils'
import type { QueryObserverResult } from '@tanstack/query-core'
import type { Writable } from 'svelte/store'
export let states: Writable<Array<QueryObserverResult>>
const queryClient = new QueryClient()
const count = writable(0)
const options = derived(count, ($count) => ({
queryKey: ['test'],
queryFn: () => sleep(10).then(() => ++$count),
}))
const query = createQuery(options, queryClient)
$: states.update((prev) => [...prev, $query])
</script>
<button on:click={() => queryClient.removeQueries({ queryKey: ['test'] })}
>Remove</button
>
<button on:click={() => $query.refetch()}>Refetch</button>
<div>Data: {$query.data ?? 'undefined'}</div>
|