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

BaseExample.svelte

29 lines881 Bytes

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