Open History to see the last commit
1<script lang="ts">
2 import { createKey, sleep } from '@tanstack/query-test-utils'
3 import { untrack } from 'svelte'
4 import { setQueryClientContext } from '../../src/context.js'
5 import { createInfiniteQuery } from '../../src/index.js'
6 import type { QueryClient, QueryObserverResult } from '@tanstack/query-core'
7β
8 type Props = {
9 queryClient: QueryClient
10 states: { value: Array<QueryObserverResult> }
11 }
12β
13 let { queryClient, states }: Props = $props()
14β
15 setQueryClientContext(queryClient)
16β
17 const query = createInfiniteQuery(() => ({
18 queryKey: createKey(),
19 queryFn: ({ pageParam }) => sleep(10).then(() => pageParam),
20 getNextPageParam: (lastPage) => lastPage + 1,
21 initialPageParam: 0,
22 }))
23β
24 $effect(() => {
25 // @ts-expect-error
26 states.value = [...untrack(() => states.value), $state.snapshot(query)]
27 })
28</script>
29β
30<div>Status: {query.status}</div>