@tanstack/react-query 5.0.0-beta.8 → 5.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/codemods/coverage/base.css +224 -0
- package/build/codemods/coverage/block-navigation.js +87 -0
- package/build/codemods/coverage/clover.xml +6 -0
- package/build/codemods/coverage/coverage-final.json +1 -0
- package/build/codemods/coverage/favicon.png +0 -0
- package/build/codemods/coverage/index.html +101 -0
- package/build/codemods/coverage/prettify.css +1 -0
- package/build/codemods/coverage/prettify.js +2 -0
- package/build/codemods/coverage/sort-arrow-sprite.png +0 -0
- package/build/codemods/coverage/sorter.js +196 -0
- package/build/legacy/HydrationBoundary.cjs +37 -2
- package/build/legacy/HydrationBoundary.cjs.map +1 -1
- package/build/legacy/HydrationBoundary.d.cts +3 -1
- package/build/legacy/HydrationBoundary.d.ts +3 -1
- package/build/legacy/HydrationBoundary.js +37 -2
- package/build/legacy/HydrationBoundary.js.map +1 -1
- package/build/legacy/index.cjs +3 -0
- package/build/legacy/index.cjs.map +1 -1
- package/build/legacy/index.d.cts +1 -0
- package/build/legacy/index.d.ts +1 -0
- package/build/legacy/index.js +2 -0
- package/build/legacy/index.js.map +1 -1
- package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.cts +1 -1
- package/build/legacy/infiniteQueryOptions.d.ts +1 -1
- package/build/legacy/infiniteQueryOptions.js.map +1 -1
- package/build/legacy/queryOptions.cjs.map +1 -1
- package/build/legacy/queryOptions.d.cts +7 -3
- package/build/legacy/queryOptions.d.ts +7 -3
- package/build/legacy/queryOptions.js.map +1 -1
- package/build/legacy/suspense.cjs +3 -0
- package/build/legacy/suspense.cjs.map +1 -1
- package/build/legacy/suspense.d.cts +3 -2
- package/build/legacy/suspense.d.ts +3 -2
- package/build/legacy/suspense.js +2 -0
- package/build/legacy/suspense.js.map +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +4 -4
- package/build/legacy/types.d.ts +4 -4
- package/build/legacy/useQueries.cjs.map +1 -1
- package/build/legacy/useQueries.d.cts +4 -4
- package/build/legacy/useQueries.d.ts +4 -4
- package/build/legacy/useQueries.js.map +1 -1
- package/build/legacy/useSuspenseQueries.cjs +47 -0
- package/build/legacy/useSuspenseQueries.cjs.map +1 -0
- package/build/legacy/useSuspenseQueries.d.cts +66 -0
- package/build/legacy/useSuspenseQueries.d.ts +66 -0
- package/build/legacy/useSuspenseQueries.js +23 -0
- package/build/legacy/useSuspenseQueries.js.map +1 -0
- package/build/legacy/useSuspenseQuery.cjs +2 -1
- package/build/legacy/useSuspenseQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseQuery.js +2 -1
- package/build/legacy/useSuspenseQuery.js.map +1 -1
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +1 -1
- package/build/legacy/utils.d.ts +1 -1
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/HydrationBoundary.cjs +37 -2
- package/build/modern/HydrationBoundary.cjs.map +1 -1
- package/build/modern/HydrationBoundary.d.cts +3 -1
- package/build/modern/HydrationBoundary.d.ts +3 -1
- package/build/modern/HydrationBoundary.js +37 -2
- package/build/modern/HydrationBoundary.js.map +1 -1
- package/build/modern/index.cjs +3 -0
- package/build/modern/index.cjs.map +1 -1
- package/build/modern/index.d.cts +1 -0
- package/build/modern/index.d.ts +1 -0
- package/build/modern/index.js +2 -0
- package/build/modern/index.js.map +1 -1
- package/build/modern/infiniteQueryOptions.cjs.map +1 -1
- package/build/modern/infiniteQueryOptions.d.cts +1 -1
- package/build/modern/infiniteQueryOptions.d.ts +1 -1
- package/build/modern/infiniteQueryOptions.js.map +1 -1
- package/build/modern/queryOptions.cjs.map +1 -1
- package/build/modern/queryOptions.d.cts +7 -3
- package/build/modern/queryOptions.d.ts +7 -3
- package/build/modern/queryOptions.js.map +1 -1
- package/build/modern/suspense.cjs +3 -0
- package/build/modern/suspense.cjs.map +1 -1
- package/build/modern/suspense.d.cts +3 -2
- package/build/modern/suspense.d.ts +3 -2
- package/build/modern/suspense.js +2 -0
- package/build/modern/suspense.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +4 -4
- package/build/modern/types.d.ts +4 -4
- package/build/modern/useQueries.cjs.map +1 -1
- package/build/modern/useQueries.d.cts +4 -4
- package/build/modern/useQueries.d.ts +4 -4
- package/build/modern/useQueries.js.map +1 -1
- package/build/modern/useSuspenseQueries.cjs +47 -0
- package/build/modern/useSuspenseQueries.cjs.map +1 -0
- package/build/modern/useSuspenseQueries.d.cts +66 -0
- package/build/modern/useSuspenseQueries.d.ts +66 -0
- package/build/modern/useSuspenseQueries.js +23 -0
- package/build/modern/useSuspenseQueries.js.map +1 -0
- package/build/modern/useSuspenseQuery.cjs +2 -1
- package/build/modern/useSuspenseQuery.cjs.map +1 -1
- package/build/modern/useSuspenseQuery.js +2 -1
- package/build/modern/useSuspenseQuery.js.map +1 -1
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +1 -1
- package/build/modern/utils.d.ts +1 -1
- package/build/modern/utils.js.map +1 -1
- package/package.json +7 -3
- package/src/HydrationBoundary.tsx +78 -8
- package/src/__tests__/HydrationBoundary.test.tsx +111 -7
- package/src/__tests__/QueryResetErrorBoundary.test.tsx +10 -6
- package/src/__tests__/fine-grained-persister.test.tsx +163 -0
- package/src/__tests__/queryOptions.types.test.tsx +31 -0
- package/src/__tests__/ssr.test.tsx +2 -2
- package/src/__tests__/suspense.test.tsx +94 -386
- package/src/__tests__/useInfiniteQuery.test.tsx +44 -44
- package/src/__tests__/useInfiniteQuery.type.test.tsx +24 -13
- package/src/__tests__/useIsFetching.test.tsx +2 -2
- package/src/__tests__/useMutation.test.tsx +4 -4
- package/src/__tests__/useMutationState.test.tsx +4 -4
- package/src/__tests__/useQueries.test.tsx +65 -64
- package/src/__tests__/useQuery.test.tsx +142 -141
- package/src/__tests__/useQuery.types.test.tsx +34 -0
- package/src/__tests__/utils.tsx +0 -7
- package/src/index.ts +5 -0
- package/src/infiniteQueryOptions.ts +3 -1
- package/src/queryOptions.ts +11 -3
- package/src/suspense.ts +12 -0
- package/src/types.ts +18 -12
- package/src/useQueries.ts +34 -28
- package/src/useSuspenseQueries.ts +164 -0
- package/src/useSuspenseQuery.ts +2 -1
- package/src/utils.ts +1 -1
|
@@ -18,7 +18,7 @@ import type {
|
|
|
18
18
|
import type { Mock } from 'vitest'
|
|
19
19
|
|
|
20
20
|
interface Result {
|
|
21
|
-
items: number
|
|
21
|
+
items: Array<number>
|
|
22
22
|
nextId?: number
|
|
23
23
|
prevId?: number
|
|
24
24
|
ts: number
|
|
@@ -47,14 +47,14 @@ describe('useInfiniteQuery', () => {
|
|
|
47
47
|
|
|
48
48
|
it('should return the correct states for a successful query', async () => {
|
|
49
49
|
const key = queryKey()
|
|
50
|
-
const states: UseInfiniteQueryResult<InfiniteData<number
|
|
50
|
+
const states: Array<UseInfiniteQueryResult<InfiniteData<number>>> = []
|
|
51
51
|
|
|
52
52
|
function Page() {
|
|
53
53
|
const state = useInfiniteQuery({
|
|
54
54
|
queryKey: key,
|
|
55
55
|
queryFn: ({ pageParam }) => Number(pageParam),
|
|
56
56
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
57
|
-
|
|
57
|
+
initialPageParam: 0,
|
|
58
58
|
})
|
|
59
59
|
states.push(state)
|
|
60
60
|
return null
|
|
@@ -149,7 +149,7 @@ describe('useInfiniteQuery', () => {
|
|
|
149
149
|
retry: 1,
|
|
150
150
|
retryDelay: 10,
|
|
151
151
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
152
|
-
|
|
152
|
+
initialPageParam: start,
|
|
153
153
|
})
|
|
154
154
|
|
|
155
155
|
const { fetchNextPage } = state
|
|
@@ -174,7 +174,7 @@ describe('useInfiniteQuery', () => {
|
|
|
174
174
|
|
|
175
175
|
it('should keep the previous data when placeholderData is set', async () => {
|
|
176
176
|
const key = queryKey()
|
|
177
|
-
const states: UseInfiniteQueryResult<InfiniteData<string
|
|
177
|
+
const states: Array<UseInfiniteQueryResult<InfiniteData<string>>> = []
|
|
178
178
|
|
|
179
179
|
function Page() {
|
|
180
180
|
const [order, setOrder] = React.useState('desc')
|
|
@@ -186,7 +186,7 @@ describe('useInfiniteQuery', () => {
|
|
|
186
186
|
return `${pageParam}-${order}`
|
|
187
187
|
},
|
|
188
188
|
getNextPageParam: () => 1,
|
|
189
|
-
|
|
189
|
+
initialPageParam: 0,
|
|
190
190
|
placeholderData: keepPreviousData,
|
|
191
191
|
notifyOnChangeProps: 'all',
|
|
192
192
|
})
|
|
@@ -262,7 +262,7 @@ describe('useInfiniteQuery', () => {
|
|
|
262
262
|
|
|
263
263
|
it('should be able to select a part of the data', async () => {
|
|
264
264
|
const key = queryKey()
|
|
265
|
-
const states: UseInfiniteQueryResult<InfiniteData<string
|
|
265
|
+
const states: Array<UseInfiniteQueryResult<InfiniteData<string>>> = []
|
|
266
266
|
|
|
267
267
|
function Page() {
|
|
268
268
|
const state = useInfiniteQuery({
|
|
@@ -273,7 +273,7 @@ describe('useInfiniteQuery', () => {
|
|
|
273
273
|
pageParams: data.pageParams,
|
|
274
274
|
}),
|
|
275
275
|
getNextPageParam: () => undefined,
|
|
276
|
-
|
|
276
|
+
initialPageParam: 0,
|
|
277
277
|
})
|
|
278
278
|
states.push(state)
|
|
279
279
|
|
|
@@ -299,9 +299,9 @@ describe('useInfiniteQuery', () => {
|
|
|
299
299
|
|
|
300
300
|
it('should be able to select a new result and not cause infinite renders', async () => {
|
|
301
301
|
const key = queryKey()
|
|
302
|
-
const states:
|
|
303
|
-
InfiniteData<{ count: number; id: number }
|
|
304
|
-
>
|
|
302
|
+
const states: Array<
|
|
303
|
+
UseInfiniteQueryResult<InfiniteData<{ count: number; id: number }>>
|
|
304
|
+
> = []
|
|
305
305
|
let selectCalled = 0
|
|
306
306
|
|
|
307
307
|
function Page() {
|
|
@@ -316,7 +316,7 @@ describe('useInfiniteQuery', () => {
|
|
|
316
316
|
}
|
|
317
317
|
}, []),
|
|
318
318
|
getNextPageParam: () => undefined,
|
|
319
|
-
|
|
319
|
+
initialPageParam: 0,
|
|
320
320
|
})
|
|
321
321
|
states.push(state)
|
|
322
322
|
|
|
@@ -349,7 +349,7 @@ describe('useInfiniteQuery', () => {
|
|
|
349
349
|
|
|
350
350
|
it('should be able to reverse the data', async () => {
|
|
351
351
|
const key = queryKey()
|
|
352
|
-
const states: UseInfiniteQueryResult<InfiniteData<number
|
|
352
|
+
const states: Array<UseInfiniteQueryResult<InfiniteData<number>>> = []
|
|
353
353
|
|
|
354
354
|
function Page() {
|
|
355
355
|
const state = useInfiniteQuery({
|
|
@@ -364,7 +364,7 @@ describe('useInfiniteQuery', () => {
|
|
|
364
364
|
}),
|
|
365
365
|
notifyOnChangeProps: 'all',
|
|
366
366
|
getNextPageParam: () => 1,
|
|
367
|
-
|
|
367
|
+
initialPageParam: 0,
|
|
368
368
|
})
|
|
369
369
|
|
|
370
370
|
states.push(state)
|
|
@@ -406,7 +406,7 @@ describe('useInfiniteQuery', () => {
|
|
|
406
406
|
|
|
407
407
|
it('should be able to fetch a previous page', async () => {
|
|
408
408
|
const key = queryKey()
|
|
409
|
-
const states: UseInfiniteQueryResult<InfiniteData<number
|
|
409
|
+
const states: Array<UseInfiniteQueryResult<InfiniteData<number>>> = []
|
|
410
410
|
|
|
411
411
|
function Page() {
|
|
412
412
|
const start = 10
|
|
@@ -416,7 +416,7 @@ describe('useInfiniteQuery', () => {
|
|
|
416
416
|
await sleep(10)
|
|
417
417
|
return Number(pageParam)
|
|
418
418
|
},
|
|
419
|
-
|
|
419
|
+
initialPageParam: start,
|
|
420
420
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
421
421
|
getPreviousPageParam: (firstPage) => firstPage - 1,
|
|
422
422
|
notifyOnChangeProps: 'all',
|
|
@@ -489,7 +489,7 @@ describe('useInfiniteQuery', () => {
|
|
|
489
489
|
|
|
490
490
|
it('should be able to refetch when providing page params automatically', async () => {
|
|
491
491
|
const key = queryKey()
|
|
492
|
-
const states: UseInfiniteQueryResult<InfiniteData<number
|
|
492
|
+
const states: Array<UseInfiniteQueryResult<InfiniteData<number>>> = []
|
|
493
493
|
|
|
494
494
|
function Page() {
|
|
495
495
|
const state = useInfiniteQuery({
|
|
@@ -498,7 +498,7 @@ describe('useInfiniteQuery', () => {
|
|
|
498
498
|
await sleep(10)
|
|
499
499
|
return Number(pageParam)
|
|
500
500
|
},
|
|
501
|
-
|
|
501
|
+
initialPageParam: 10,
|
|
502
502
|
getPreviousPageParam: (firstPage) => firstPage - 1,
|
|
503
503
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
504
504
|
notifyOnChangeProps: 'all',
|
|
@@ -608,7 +608,7 @@ describe('useInfiniteQuery', () => {
|
|
|
608
608
|
await sleep(50)
|
|
609
609
|
return Number(pageParam)
|
|
610
610
|
},
|
|
611
|
-
|
|
611
|
+
initialPageParam: start,
|
|
612
612
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
613
613
|
})
|
|
614
614
|
|
|
@@ -644,8 +644,8 @@ describe('useInfiniteQuery', () => {
|
|
|
644
644
|
it('should silently cancel an ongoing fetchNextPage request when another fetchNextPage is invoked', async () => {
|
|
645
645
|
const key = queryKey()
|
|
646
646
|
const start = 10
|
|
647
|
-
const onAborts: Mock<any, any
|
|
648
|
-
const abortListeners: Mock<any, any
|
|
647
|
+
const onAborts: Array<Mock<any, any>> = []
|
|
648
|
+
const abortListeners: Array<Mock<any, any>> = []
|
|
649
649
|
const fetchPage = vi.fn<
|
|
650
650
|
[QueryFunctionContext<typeof key, number>],
|
|
651
651
|
Promise<number>
|
|
@@ -664,7 +664,7 @@ describe('useInfiniteQuery', () => {
|
|
|
664
664
|
const { fetchNextPage } = useInfiniteQuery({
|
|
665
665
|
queryKey: key,
|
|
666
666
|
queryFn: fetchPage,
|
|
667
|
-
|
|
667
|
+
initialPageParam: start,
|
|
668
668
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
669
669
|
})
|
|
670
670
|
|
|
@@ -720,8 +720,8 @@ describe('useInfiniteQuery', () => {
|
|
|
720
720
|
it('should not cancel an ongoing fetchNextPage request when another fetchNextPage is invoked if `cancelRefetch: false` is used ', async () => {
|
|
721
721
|
const key = queryKey()
|
|
722
722
|
const start = 10
|
|
723
|
-
const onAborts: Mock<any, any
|
|
724
|
-
const abortListeners: Mock<any, any
|
|
723
|
+
const onAborts: Array<Mock<any, any>> = []
|
|
724
|
+
const abortListeners: Array<Mock<any, any>> = []
|
|
725
725
|
const fetchPage = vi.fn<
|
|
726
726
|
[QueryFunctionContext<typeof key, number>],
|
|
727
727
|
Promise<number>
|
|
@@ -741,7 +741,7 @@ describe('useInfiniteQuery', () => {
|
|
|
741
741
|
const { fetchNextPage } = useInfiniteQuery({
|
|
742
742
|
queryKey: key,
|
|
743
743
|
queryFn: fetchPage,
|
|
744
|
-
|
|
744
|
+
initialPageParam: start,
|
|
745
745
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
746
746
|
})
|
|
747
747
|
|
|
@@ -787,7 +787,7 @@ describe('useInfiniteQuery', () => {
|
|
|
787
787
|
|
|
788
788
|
it('should keep fetching first page when not loaded yet and triggering fetch more', async () => {
|
|
789
789
|
const key = queryKey()
|
|
790
|
-
const states: UseInfiniteQueryResult<InfiniteData<number
|
|
790
|
+
const states: Array<UseInfiniteQueryResult<InfiniteData<number>>> = []
|
|
791
791
|
|
|
792
792
|
function Page() {
|
|
793
793
|
const start = 10
|
|
@@ -797,7 +797,7 @@ describe('useInfiniteQuery', () => {
|
|
|
797
797
|
await sleep(50)
|
|
798
798
|
return Number(pageParam)
|
|
799
799
|
},
|
|
800
|
-
|
|
800
|
+
initialPageParam: start,
|
|
801
801
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
802
802
|
notifyOnChangeProps: 'all',
|
|
803
803
|
})
|
|
@@ -851,7 +851,7 @@ describe('useInfiniteQuery', () => {
|
|
|
851
851
|
return Number(pageParam) * 10
|
|
852
852
|
},
|
|
853
853
|
initialData,
|
|
854
|
-
|
|
854
|
+
initialPageParam: 0,
|
|
855
855
|
getNextPageParam: (_, allPages) => {
|
|
856
856
|
return allPages.length === 4 ? undefined : allPages.length
|
|
857
857
|
},
|
|
@@ -886,7 +886,7 @@ describe('useInfiniteQuery', () => {
|
|
|
886
886
|
|
|
887
887
|
it('should be able to set new pages with the query client', async () => {
|
|
888
888
|
const key = queryKey()
|
|
889
|
-
const states: UseInfiniteQueryResult<InfiniteData<number
|
|
889
|
+
const states: Array<UseInfiniteQueryResult<InfiniteData<number>>> = []
|
|
890
890
|
|
|
891
891
|
function Page() {
|
|
892
892
|
const [firstPage, setFirstPage] = React.useState(0)
|
|
@@ -898,7 +898,7 @@ describe('useInfiniteQuery', () => {
|
|
|
898
898
|
return Number(pageParam)
|
|
899
899
|
},
|
|
900
900
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
901
|
-
|
|
901
|
+
initialPageParam: firstPage,
|
|
902
902
|
notifyOnChangeProps: 'all',
|
|
903
903
|
})
|
|
904
904
|
|
|
@@ -968,7 +968,7 @@ describe('useInfiniteQuery', () => {
|
|
|
968
968
|
|
|
969
969
|
it('should only refetch the first page when initialData is provided', async () => {
|
|
970
970
|
const key = queryKey()
|
|
971
|
-
const states: UseInfiniteQueryResult<InfiniteData<number
|
|
971
|
+
const states: Array<UseInfiniteQueryResult<InfiniteData<number>>> = []
|
|
972
972
|
|
|
973
973
|
function Page() {
|
|
974
974
|
const state = useInfiniteQuery({
|
|
@@ -979,7 +979,7 @@ describe('useInfiniteQuery', () => {
|
|
|
979
979
|
},
|
|
980
980
|
initialData: { pages: [1], pageParams: [1] },
|
|
981
981
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
982
|
-
|
|
982
|
+
initialPageParam: 0,
|
|
983
983
|
notifyOnChangeProps: 'all',
|
|
984
984
|
})
|
|
985
985
|
|
|
@@ -1033,14 +1033,14 @@ describe('useInfiniteQuery', () => {
|
|
|
1033
1033
|
|
|
1034
1034
|
it('should set hasNextPage to false if getNextPageParam returns undefined', async () => {
|
|
1035
1035
|
const key = queryKey()
|
|
1036
|
-
const states: UseInfiniteQueryResult<InfiniteData<number
|
|
1036
|
+
const states: Array<UseInfiniteQueryResult<InfiniteData<number>>> = []
|
|
1037
1037
|
|
|
1038
1038
|
function Page() {
|
|
1039
1039
|
const state = useInfiniteQuery({
|
|
1040
1040
|
queryKey: key,
|
|
1041
1041
|
queryFn: ({ pageParam }) => Number(pageParam),
|
|
1042
1042
|
getNextPageParam: () => undefined,
|
|
1043
|
-
|
|
1043
|
+
initialPageParam: 1,
|
|
1044
1044
|
})
|
|
1045
1045
|
|
|
1046
1046
|
states.push(state)
|
|
@@ -1071,7 +1071,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1071
1071
|
|
|
1072
1072
|
it('should compute hasNextPage correctly using initialData', async () => {
|
|
1073
1073
|
const key = queryKey()
|
|
1074
|
-
const states: UseInfiniteQueryResult<InfiniteData<number
|
|
1074
|
+
const states: Array<UseInfiniteQueryResult<InfiniteData<number>>> = []
|
|
1075
1075
|
|
|
1076
1076
|
function Page() {
|
|
1077
1077
|
const state = useInfiniteQuery({
|
|
@@ -1079,7 +1079,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1079
1079
|
queryFn: ({ pageParam }): number => pageParam,
|
|
1080
1080
|
initialData: { pages: [10], pageParams: [10] },
|
|
1081
1081
|
getNextPageParam: (lastPage) => (lastPage === 10 ? 11 : undefined),
|
|
1082
|
-
|
|
1082
|
+
initialPageParam: 10,
|
|
1083
1083
|
})
|
|
1084
1084
|
|
|
1085
1085
|
states.push(state)
|
|
@@ -1110,13 +1110,13 @@ describe('useInfiniteQuery', () => {
|
|
|
1110
1110
|
|
|
1111
1111
|
it('should compute hasNextPage correctly for falsy getFetchMore return value using initialData', async () => {
|
|
1112
1112
|
const key = queryKey()
|
|
1113
|
-
const states: UseInfiniteQueryResult<InfiniteData<number
|
|
1113
|
+
const states: Array<UseInfiniteQueryResult<InfiniteData<number>>> = []
|
|
1114
1114
|
|
|
1115
1115
|
function Page() {
|
|
1116
1116
|
const state = useInfiniteQuery({
|
|
1117
1117
|
queryKey: key,
|
|
1118
1118
|
queryFn: ({ pageParam }): number => pageParam,
|
|
1119
|
-
|
|
1119
|
+
initialPageParam: 10,
|
|
1120
1120
|
initialData: { pages: [10], pageParams: [10] },
|
|
1121
1121
|
getNextPageParam: () => undefined,
|
|
1122
1122
|
})
|
|
@@ -1149,7 +1149,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1149
1149
|
|
|
1150
1150
|
it('should not use selected data when computing hasNextPage', async () => {
|
|
1151
1151
|
const key = queryKey()
|
|
1152
|
-
const states: UseInfiniteQueryResult<InfiniteData<string
|
|
1152
|
+
const states: Array<UseInfiniteQueryResult<InfiniteData<string>>> = []
|
|
1153
1153
|
|
|
1154
1154
|
function Page() {
|
|
1155
1155
|
const state = useInfiniteQuery({
|
|
@@ -1160,7 +1160,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1160
1160
|
pages: data.pages.map((x) => x.toString()),
|
|
1161
1161
|
pageParams: data.pageParams,
|
|
1162
1162
|
}),
|
|
1163
|
-
|
|
1163
|
+
initialPageParam: 1,
|
|
1164
1164
|
})
|
|
1165
1165
|
|
|
1166
1166
|
states.push(state)
|
|
@@ -1220,7 +1220,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1220
1220
|
queryKey: key,
|
|
1221
1221
|
queryFn: ({ pageParam }) =>
|
|
1222
1222
|
fetchItemsWithLimit(pageParam, fetchCountRef.current++),
|
|
1223
|
-
|
|
1223
|
+
initialPageParam: 0,
|
|
1224
1224
|
getNextPageParam: (lastPage) => lastPage.nextId,
|
|
1225
1225
|
})
|
|
1226
1226
|
|
|
@@ -1350,7 +1350,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1350
1350
|
pageParam === MAX || (pageParam === MAX - 1 && isRemovedLastPage),
|
|
1351
1351
|
),
|
|
1352
1352
|
getNextPageParam: (lastPage) => lastPage.nextId,
|
|
1353
|
-
|
|
1353
|
+
initialPageParam: 0,
|
|
1354
1354
|
})
|
|
1355
1355
|
|
|
1356
1356
|
return (
|
|
@@ -1472,7 +1472,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1472
1472
|
queryKey: key,
|
|
1473
1473
|
queryFn,
|
|
1474
1474
|
getNextPageParam: () => undefined,
|
|
1475
|
-
|
|
1475
|
+
initialPageParam: 0,
|
|
1476
1476
|
})
|
|
1477
1477
|
return (
|
|
1478
1478
|
<div>
|
|
@@ -1516,7 +1516,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1516
1516
|
queryKey: key,
|
|
1517
1517
|
queryFn,
|
|
1518
1518
|
getNextPageParam: () => undefined,
|
|
1519
|
-
|
|
1519
|
+
initialPageParam: 0,
|
|
1520
1520
|
},
|
|
1521
1521
|
queryClient,
|
|
1522
1522
|
)
|
|
@@ -6,7 +6,7 @@ import type { Equal, Expect } from './utils'
|
|
|
6
6
|
import type { InfiniteData } from '@tanstack/query-core'
|
|
7
7
|
|
|
8
8
|
describe('pageParam', () => {
|
|
9
|
-
it('
|
|
9
|
+
it('initialPageParam should define type of param passed to queryFunctionContext', () => {
|
|
10
10
|
doNotExecute(() => {
|
|
11
11
|
useInfiniteQuery({
|
|
12
12
|
queryKey: ['key'],
|
|
@@ -14,7 +14,7 @@ describe('pageParam', () => {
|
|
|
14
14
|
const result: Expect<Equal<number, typeof pageParam>> = true
|
|
15
15
|
return result
|
|
16
16
|
},
|
|
17
|
-
|
|
17
|
+
initialPageParam: 1,
|
|
18
18
|
getNextPageParam: () => undefined,
|
|
19
19
|
})
|
|
20
20
|
})
|
|
@@ -30,7 +30,7 @@ describe('pageParam', () => {
|
|
|
30
30
|
> = true
|
|
31
31
|
return result
|
|
32
32
|
},
|
|
33
|
-
|
|
33
|
+
initialPageParam: 1,
|
|
34
34
|
getNextPageParam: () => undefined,
|
|
35
35
|
})
|
|
36
36
|
})
|
|
@@ -60,7 +60,7 @@ describe('pageParam', () => {
|
|
|
60
60
|
})
|
|
61
61
|
})
|
|
62
62
|
|
|
63
|
-
it('
|
|
63
|
+
it('initialPageParam should define type of param passed to queryFunctionContext for fetchInfiniteQuery', () => {
|
|
64
64
|
doNotExecute(() => {
|
|
65
65
|
const queryClient = new QueryClient()
|
|
66
66
|
queryClient.fetchInfiniteQuery({
|
|
@@ -69,12 +69,12 @@ describe('pageParam', () => {
|
|
|
69
69
|
const result: Expect<Equal<number, typeof pageParam>> = true
|
|
70
70
|
return result
|
|
71
71
|
},
|
|
72
|
-
|
|
72
|
+
initialPageParam: 1,
|
|
73
73
|
})
|
|
74
74
|
})
|
|
75
75
|
})
|
|
76
76
|
|
|
77
|
-
it('
|
|
77
|
+
it('initialPageParam should define type of param passed to queryFunctionContext for prefetchInfiniteQuery', () => {
|
|
78
78
|
doNotExecute(() => {
|
|
79
79
|
const queryClient = new QueryClient()
|
|
80
80
|
queryClient.prefetchInfiniteQuery({
|
|
@@ -83,7 +83,7 @@ describe('pageParam', () => {
|
|
|
83
83
|
const result: Expect<Equal<number, typeof pageParam>> = true
|
|
84
84
|
return result
|
|
85
85
|
},
|
|
86
|
-
|
|
86
|
+
initialPageParam: 1,
|
|
87
87
|
})
|
|
88
88
|
})
|
|
89
89
|
})
|
|
@@ -96,13 +96,18 @@ describe('select', () => {
|
|
|
96
96
|
queryFn: ({ pageParam }) => {
|
|
97
97
|
return pageParam * 5
|
|
98
98
|
},
|
|
99
|
-
|
|
99
|
+
initialPageParam: 1,
|
|
100
100
|
getNextPageParam: () => undefined,
|
|
101
101
|
})
|
|
102
102
|
|
|
103
|
+
// TODO: Order of generics prevents pageParams to be typed correctly. Using `unknown` for now
|
|
103
104
|
const result: Expect<
|
|
104
|
-
Equal<
|
|
105
|
+
Equal<
|
|
106
|
+
InfiniteData<number, unknown> | undefined,
|
|
107
|
+
(typeof infiniteQuery)['data']
|
|
108
|
+
>
|
|
105
109
|
> = true
|
|
110
|
+
|
|
106
111
|
return result
|
|
107
112
|
})
|
|
108
113
|
})
|
|
@@ -114,10 +119,12 @@ describe('select', () => {
|
|
|
114
119
|
queryFn: ({ pageParam }) => {
|
|
115
120
|
return pageParam * 5
|
|
116
121
|
},
|
|
117
|
-
|
|
122
|
+
initialPageParam: 1,
|
|
118
123
|
getNextPageParam: () => undefined,
|
|
119
124
|
select: (data) => {
|
|
120
|
-
const result: Expect<
|
|
125
|
+
const result: Expect<
|
|
126
|
+
Equal<InfiniteData<number, number>, typeof data>
|
|
127
|
+
> = true
|
|
121
128
|
return result
|
|
122
129
|
},
|
|
123
130
|
})
|
|
@@ -137,7 +144,7 @@ describe('getNextPageParam / getPreviousPageParam', () => {
|
|
|
137
144
|
queryFn: ({ pageParam }) => {
|
|
138
145
|
return String(pageParam)
|
|
139
146
|
},
|
|
140
|
-
|
|
147
|
+
initialPageParam: 1,
|
|
141
148
|
getNextPageParam: (
|
|
142
149
|
lastPage,
|
|
143
150
|
allPages,
|
|
@@ -203,8 +210,12 @@ describe('getNextPageParam / getPreviousPageParam', () => {
|
|
|
203
210
|
},
|
|
204
211
|
})
|
|
205
212
|
|
|
213
|
+
// TODO: Order of generics prevents pageParams to be typed correctly. Using `unknown` for now
|
|
206
214
|
const result: Expect<
|
|
207
|
-
Equal<
|
|
215
|
+
Equal<
|
|
216
|
+
InfiniteData<string, unknown> | undefined,
|
|
217
|
+
(typeof infiniteQuery)['data']
|
|
218
|
+
>
|
|
208
219
|
> = true
|
|
209
220
|
return result
|
|
210
221
|
})
|
|
@@ -61,7 +61,7 @@ describe('useIsFetching', () => {
|
|
|
61
61
|
const key1 = queryKey()
|
|
62
62
|
const key2 = queryKey()
|
|
63
63
|
|
|
64
|
-
const isFetchings: number
|
|
64
|
+
const isFetchings: Array<number> = []
|
|
65
65
|
|
|
66
66
|
function IsFetching() {
|
|
67
67
|
const isFetching = useIsFetching()
|
|
@@ -118,7 +118,7 @@ describe('useIsFetching', () => {
|
|
|
118
118
|
const key1 = queryKey()
|
|
119
119
|
const key2 = queryKey()
|
|
120
120
|
|
|
121
|
-
const isFetchings: number
|
|
121
|
+
const isFetchings: Array<number> = []
|
|
122
122
|
|
|
123
123
|
function One() {
|
|
124
124
|
useQuery({
|
|
@@ -267,7 +267,7 @@ describe('useMutation', () => {
|
|
|
267
267
|
})
|
|
268
268
|
|
|
269
269
|
it('should be able to override the useMutation success callbacks', async () => {
|
|
270
|
-
const callbacks: string
|
|
270
|
+
const callbacks: Array<string> = []
|
|
271
271
|
|
|
272
272
|
function Page() {
|
|
273
273
|
const { mutateAsync } = useMutation({
|
|
@@ -313,7 +313,7 @@ describe('useMutation', () => {
|
|
|
313
313
|
})
|
|
314
314
|
|
|
315
315
|
it('should be able to override the error callbacks when using mutateAsync', async () => {
|
|
316
|
-
const callbacks: string
|
|
316
|
+
const callbacks: Array<string> = []
|
|
317
317
|
|
|
318
318
|
function Page() {
|
|
319
319
|
const { mutateAsync } = useMutation({
|
|
@@ -369,7 +369,7 @@ describe('useMutation', () => {
|
|
|
369
369
|
},
|
|
370
370
|
})
|
|
371
371
|
|
|
372
|
-
const states: UseMutationResult<any, any, any, any
|
|
372
|
+
const states: Array<UseMutationResult<any, any, any, any>> = []
|
|
373
373
|
|
|
374
374
|
function Page() {
|
|
375
375
|
const state = useMutation<string, unknown, string>({ mutationKey: key })
|
|
@@ -586,7 +586,7 @@ describe('useMutation', () => {
|
|
|
586
586
|
const onlineMock = mockOnlineManagerIsOnline(false)
|
|
587
587
|
|
|
588
588
|
let count = 0
|
|
589
|
-
const states: UseMutationResult<any, any, any, any
|
|
589
|
+
const states: Array<UseMutationResult<any, any, any, any>> = []
|
|
590
590
|
|
|
591
591
|
function Page() {
|
|
592
592
|
const state = useMutation({
|
|
@@ -13,7 +13,7 @@ import type { MutationState, MutationStatus } from '@tanstack/query-core'
|
|
|
13
13
|
|
|
14
14
|
describe('useIsMutating', () => {
|
|
15
15
|
it('should return the number of fetching mutations', async () => {
|
|
16
|
-
const isMutatings: number
|
|
16
|
+
const isMutatings: Array<number> = []
|
|
17
17
|
const queryClient = createQueryClient()
|
|
18
18
|
|
|
19
19
|
function IsMutating() {
|
|
@@ -62,7 +62,7 @@ describe('useIsMutating', () => {
|
|
|
62
62
|
})
|
|
63
63
|
|
|
64
64
|
it('should filter correctly by mutationKey', async () => {
|
|
65
|
-
const isMutatings: number
|
|
65
|
+
const isMutatings: Array<number> = []
|
|
66
66
|
const queryClient = createQueryClient()
|
|
67
67
|
|
|
68
68
|
function IsMutating() {
|
|
@@ -100,7 +100,7 @@ describe('useIsMutating', () => {
|
|
|
100
100
|
})
|
|
101
101
|
|
|
102
102
|
it('should filter correctly by predicate', async () => {
|
|
103
|
-
const isMutatings: number
|
|
103
|
+
const isMutatings: Array<number> = []
|
|
104
104
|
const queryClient = createQueryClient()
|
|
105
105
|
|
|
106
106
|
function IsMutating() {
|
|
@@ -197,7 +197,7 @@ describe('useMutationState', () => {
|
|
|
197
197
|
})
|
|
198
198
|
it('should return variables after calling mutate', async () => {
|
|
199
199
|
const queryClient = createQueryClient()
|
|
200
|
-
const variables: unknown
|
|
200
|
+
const variables: Array<Array<unknown>> = []
|
|
201
201
|
const mutationKey = ['mutation']
|
|
202
202
|
|
|
203
203
|
function Variables() {
|