-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathSelectExample.svelte
More file actions
36 lines (31 loc) · 1.02 KB
/
SelectExample.svelte
File metadata and controls
36 lines (31 loc) · 1.02 KB
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
34
35
36
<script lang="ts">
import { untrack } from 'svelte'
import { createInfiniteQuery } from '../../src/index.js'
import { setQueryClientContext } from '../../src/context.js'
import type { QueryClient, QueryObserverResult } from '@tanstack/query-core'
import { queryKey, sleep } from '@tanstack/query-test-utils'
let {
queryClient,
states,
}: {
queryClient: QueryClient
states: { value: Array<QueryObserverResult> }
} = $props()
setQueryClientContext(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,
}))
$effect(() => {
// @ts-expect-error
// svelte-ignore state_snapshot_uncloneable
states.value = [...untrack(() => states.value), $state.snapshot(query)]
})
</script>
<div>{query.data?.pages.join(',')}</div>