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: () => sleep(10).then(() => ({ count: 1 })),
20 select: (data) => ({
21 pages: data.pages.map((x) => `count: ${x.count}`),
22 pageParams: data.pageParams,
23 }),
24 getNextPageParam: () => undefined,
25 initialPageParam: 0,
26 }))
27β
28 $effect(() => {
29 // @ts-expect-error
30 states.value = [...untrack(() => states.value), $state.snapshot(query)]
31 })
32</script>
33β
34<div>{query.data?.pages.join(',')}</div>