-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathChangeClientExample.svelte
More file actions
39 lines (31 loc) · 885 Bytes
/
ChangeClientExample.svelte
File metadata and controls
39 lines (31 loc) · 885 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
34
35
36
37
38
39
<script lang="ts">
import { QueryClient } from '@tanstack/query-core'
import { createInfiniteQuery } from '../../src/index.js'
import { setQueryClientContext } from '../../src/context.js'
import { sleep } from '@tanstack/query-test-utils'
type Props = {
queryClient: QueryClient
}
let { queryClient }: Props = $props()
const queryKey = ['test']
let firstPage = $state(0)
setQueryClientContext(queryClient)
const query = createInfiniteQuery(() => ({
queryKey: queryKey,
queryFn: ({ pageParam }) => sleep(10).then(() => pageParam),
getNextPageParam: (lastPage) => lastPage + 1,
initialPageParam: firstPage,
}))
</script>
<button
onclick={() => {
queryClient.setQueryData(queryKey, {
pages: [7, 8],
pageParams: [7, 8],
})
firstPage = 7
}}
>
setPages
</button>
<div>Data: {JSON.stringify(query.data)}</div>