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

ChangeClient.svelte

35 lines798 Bytes

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