-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathSelectExample.svelte
More file actions
33 lines (28 loc) · 1014 Bytes
/
SelectExample.svelte
File metadata and controls
33 lines (28 loc) · 1014 Bytes
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
31
32
33
<script lang="ts">
import { untrack } from 'svelte'
import { QueryClient } from '@tanstack/query-core'
import { createInfiniteQuery } from '../../src/index.js'
import type { QueryObserverResult } from '@tanstack/query-core'
import { queryKey, sleep } from '@tanstack/query-test-utils'
let { states }: { states: { value: Array<QueryObserverResult> } } = $props()
const queryClient = new QueryClient()
const query = createInfiniteQuery(
() => ({
queryKey: queryKey(),
queryFn: () => sleep(10).then(() => ({ count: 1 })),
select: (data) => ({
pages: data.pages.map((x) => `count: ${x.count}`),
pageParams: data.pageParams,
}),
getNextPageParam: () => undefined,
initialPageParam: 0,
}),
() => queryClient,
)
$effect(() => {
// @ts-expect-error
// svelte-ignore state_snapshot_uncloneable
states.value = [...untrack(() => states.value), $state.snapshot(query)]
})
</script>
<div>{query.data?.pages.join(',')}</div>