Open History to see the last commit
1<script lang="ts">
2 import { QueryClient } from '@tanstack/query-core'
3 import { sleep } from '@tanstack/query-test-utils'
4 import { setQueryClientContext } from '../../src/context.js'
5 import { createInfiniteQuery } from '../../src/index.js'
6β
7 type Props = {
8 queryClient: QueryClient
9 }
10β
11 let { queryClient }: Props = $props()
12β
13 const queryKey = ['test']
14β
15 let firstPage = $state(0)
16β
17 setQueryClientContext(queryClient)
18β
19 const query = createInfiniteQuery(() => ({
20 queryKey: queryKey,
21 queryFn: ({ pageParam }) => sleep(10).then(() => pageParam),
22 getNextPageParam: (lastPage) => lastPage + 1,
23 initialPageParam: firstPage,
24 }))
25</script>
26β
27<button
28 onclick={() => {
29 queryClient.setQueryData(queryKey, {
30 pages: [7, 8],
31 pageParams: [7, 8],
32 })
33 firstPage = 7
34 }}
35>
36 setPages
37</button>
38β
39<div>Data: {JSON.stringify(query.data)}</div>