@tanstack/react-query 5.104.0 → 5.104.2
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/legacy/HydrationBoundary.cjs +2 -3
- package/build/legacy/HydrationBoundary.cjs.map +1 -1
- package/build/legacy/HydrationBoundary.d.cts +2 -3
- package/build/legacy/HydrationBoundary.d.cts.map +1 -1
- package/build/legacy/HydrationBoundary.d.ts +2 -3
- package/build/legacy/HydrationBoundary.d.ts.map +1 -1
- package/build/legacy/HydrationBoundary.js +2 -3
- package/build/legacy/HydrationBoundary.js.map +1 -1
- package/build/legacy/IsRestoringProvider.cjs +0 -1
- package/build/legacy/IsRestoringProvider.cjs.map +1 -1
- package/build/legacy/IsRestoringProvider.d.cts +0 -1
- package/build/legacy/IsRestoringProvider.d.cts.map +1 -1
- package/build/legacy/IsRestoringProvider.d.ts +0 -1
- package/build/legacy/IsRestoringProvider.d.ts.map +1 -1
- package/build/legacy/IsRestoringProvider.js +0 -1
- package/build/legacy/IsRestoringProvider.js.map +1 -1
- package/build/legacy/QueryClientProvider.cjs +3 -4
- package/build/legacy/QueryClientProvider.cjs.map +1 -1
- package/build/legacy/QueryClientProvider.d.cts +3 -4
- package/build/legacy/QueryClientProvider.d.cts.map +1 -1
- package/build/legacy/QueryClientProvider.d.ts +3 -4
- package/build/legacy/QueryClientProvider.d.ts.map +1 -1
- package/build/legacy/QueryClientProvider.js +3 -4
- package/build/legacy/QueryClientProvider.js.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.cjs +5 -5
- package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.cts +23 -5
- package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.ts +23 -5
- package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.js +5 -5
- package/build/legacy/QueryErrorResetBoundary.js.map +1 -1
- package/build/legacy/errorBoundaryUtils.cjs +21 -0
- package/build/legacy/errorBoundaryUtils.cjs.map +1 -1
- package/build/legacy/errorBoundaryUtils.d.cts +21 -0
- package/build/legacy/errorBoundaryUtils.d.cts.map +1 -1
- package/build/legacy/errorBoundaryUtils.d.ts +21 -0
- package/build/legacy/errorBoundaryUtils.d.ts.map +1 -1
- package/build/legacy/errorBoundaryUtils.js +21 -0
- package/build/legacy/errorBoundaryUtils.js.map +1 -1
- package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.cts +5 -16
- package/build/legacy/infiniteQueryOptions.d.cts.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.ts +5 -16
- package/build/legacy/infiniteQueryOptions.d.ts.map +1 -1
- package/build/legacy/infiniteQueryOptions.js.map +1 -1
- package/build/legacy/mutationOptions.cjs.map +1 -1
- package/build/legacy/mutationOptions.d.cts +2 -6
- package/build/legacy/mutationOptions.d.cts.map +1 -1
- package/build/legacy/mutationOptions.d.ts +2 -6
- package/build/legacy/mutationOptions.d.ts.map +1 -1
- package/build/legacy/mutationOptions.js.map +1 -1
- package/build/legacy/queryOptions.cjs.map +1 -1
- package/build/legacy/queryOptions.d.cts +6 -16
- package/build/legacy/queryOptions.d.cts.map +1 -1
- package/build/legacy/queryOptions.d.ts +6 -16
- package/build/legacy/queryOptions.d.ts.map +1 -1
- package/build/legacy/queryOptions.js.map +1 -1
- package/build/legacy/suspense.cjs +27 -0
- package/build/legacy/suspense.cjs.map +1 -1
- package/build/legacy/suspense.d.cts +27 -0
- package/build/legacy/suspense.d.cts.map +1 -1
- package/build/legacy/suspense.d.ts +27 -0
- package/build/legacy/suspense.d.ts.map +1 -1
- package/build/legacy/suspense.js +27 -0
- package/build/legacy/suspense.js.map +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +2 -22
- package/build/legacy/types.d.cts.map +1 -1
- package/build/legacy/types.d.ts +2 -22
- package/build/legacy/types.d.ts.map +1 -1
- package/build/legacy/types.js.map +1 -1
- package/build/legacy/useBaseQuery.cjs +13 -0
- package/build/legacy/useBaseQuery.cjs.map +1 -1
- package/build/legacy/useBaseQuery.d.cts +13 -0
- package/build/legacy/useBaseQuery.d.cts.map +1 -1
- package/build/legacy/useBaseQuery.d.ts +13 -0
- package/build/legacy/useBaseQuery.d.ts.map +1 -1
- package/build/legacy/useBaseQuery.js +13 -0
- package/build/legacy/useBaseQuery.js.map +1 -1
- package/build/legacy/useInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useInfiniteQuery.d.cts +12 -21
- package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useInfiniteQuery.d.ts +12 -21
- package/build/legacy/useInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useInfiniteQuery.js.map +1 -1
- package/build/legacy/useIsFetching.cjs +0 -3
- package/build/legacy/useIsFetching.cjs.map +1 -1
- package/build/legacy/useIsFetching.d.cts +0 -3
- package/build/legacy/useIsFetching.d.cts.map +1 -1
- package/build/legacy/useIsFetching.d.ts +0 -3
- package/build/legacy/useIsFetching.d.ts.map +1 -1
- package/build/legacy/useIsFetching.js +0 -3
- package/build/legacy/useIsFetching.js.map +1 -1
- package/build/legacy/useMutation.cjs +4 -8
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.d.cts +4 -8
- package/build/legacy/useMutation.d.cts.map +1 -1
- package/build/legacy/useMutation.d.ts +4 -8
- package/build/legacy/useMutation.d.ts.map +1 -1
- package/build/legacy/useMutation.js +4 -8
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/useMutationState.cjs +13 -12
- package/build/legacy/useMutationState.cjs.map +1 -1
- package/build/legacy/useMutationState.d.cts +0 -6
- package/build/legacy/useMutationState.d.cts.map +1 -1
- package/build/legacy/useMutationState.d.ts +0 -6
- package/build/legacy/useMutationState.d.ts.map +1 -1
- package/build/legacy/useMutationState.js +13 -12
- package/build/legacy/useMutationState.js.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.cjs +0 -3
- package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.cts +0 -3
- package/build/legacy/usePrefetchInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.ts +0 -3
- package/build/legacy/usePrefetchInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.js +0 -3
- package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -1
- package/build/legacy/usePrefetchQuery.cjs +0 -3
- package/build/legacy/usePrefetchQuery.cjs.map +1 -1
- package/build/legacy/usePrefetchQuery.d.cts +0 -3
- package/build/legacy/usePrefetchQuery.d.cts.map +1 -1
- package/build/legacy/usePrefetchQuery.d.ts +0 -3
- package/build/legacy/usePrefetchQuery.d.ts.map +1 -1
- package/build/legacy/usePrefetchQuery.js +0 -3
- package/build/legacy/usePrefetchQuery.js.map +1 -1
- package/build/legacy/useQueries.cjs +7 -8
- package/build/legacy/useQueries.cjs.map +1 -1
- package/build/legacy/useQueries.d.cts +7 -11
- package/build/legacy/useQueries.d.cts.map +1 -1
- package/build/legacy/useQueries.d.ts +7 -11
- package/build/legacy/useQueries.d.ts.map +1 -1
- package/build/legacy/useQueries.js +7 -8
- package/build/legacy/useQueries.js.map +1 -1
- package/build/legacy/useQuery.cjs.map +1 -1
- package/build/legacy/useQuery.d.cts +8 -13
- package/build/legacy/useQuery.d.cts.map +1 -1
- package/build/legacy/useQuery.d.ts +8 -13
- package/build/legacy/useQuery.d.ts.map +1 -1
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.cjs +6 -8
- package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.cts +6 -8
- package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.ts +6 -8
- package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.js +6 -8
- package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/legacy/useSuspenseQueries.cjs.map +1 -1
- package/build/legacy/useSuspenseQueries.d.cts +0 -9
- package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
- package/build/legacy/useSuspenseQueries.d.ts +0 -9
- package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
- package/build/legacy/useSuspenseQueries.js.map +1 -1
- package/build/legacy/useSuspenseQuery.cjs +4 -6
- package/build/legacy/useSuspenseQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseQuery.d.cts +4 -6
- package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseQuery.d.ts +4 -6
- package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseQuery.js +4 -6
- package/build/legacy/useSuspenseQuery.js.map +1 -1
- package/build/modern/HydrationBoundary.cjs +2 -3
- package/build/modern/HydrationBoundary.cjs.map +1 -1
- package/build/modern/HydrationBoundary.d.cts +2 -3
- package/build/modern/HydrationBoundary.d.cts.map +1 -1
- package/build/modern/HydrationBoundary.d.ts +2 -3
- package/build/modern/HydrationBoundary.d.ts.map +1 -1
- package/build/modern/HydrationBoundary.js +2 -3
- package/build/modern/HydrationBoundary.js.map +1 -1
- package/build/modern/IsRestoringProvider.cjs +0 -1
- package/build/modern/IsRestoringProvider.cjs.map +1 -1
- package/build/modern/IsRestoringProvider.d.cts +0 -1
- package/build/modern/IsRestoringProvider.d.cts.map +1 -1
- package/build/modern/IsRestoringProvider.d.ts +0 -1
- package/build/modern/IsRestoringProvider.d.ts.map +1 -1
- package/build/modern/IsRestoringProvider.js +0 -1
- package/build/modern/IsRestoringProvider.js.map +1 -1
- package/build/modern/QueryClientProvider.cjs +3 -4
- package/build/modern/QueryClientProvider.cjs.map +1 -1
- package/build/modern/QueryClientProvider.d.cts +3 -4
- package/build/modern/QueryClientProvider.d.cts.map +1 -1
- package/build/modern/QueryClientProvider.d.ts +3 -4
- package/build/modern/QueryClientProvider.d.ts.map +1 -1
- package/build/modern/QueryClientProvider.js +3 -4
- package/build/modern/QueryClientProvider.js.map +1 -1
- package/build/modern/QueryErrorResetBoundary.cjs +5 -5
- package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.cts +23 -5
- package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.ts +23 -5
- package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.js +5 -5
- package/build/modern/QueryErrorResetBoundary.js.map +1 -1
- package/build/modern/errorBoundaryUtils.cjs +21 -0
- package/build/modern/errorBoundaryUtils.cjs.map +1 -1
- package/build/modern/errorBoundaryUtils.d.cts +21 -0
- package/build/modern/errorBoundaryUtils.d.cts.map +1 -1
- package/build/modern/errorBoundaryUtils.d.ts +21 -0
- package/build/modern/errorBoundaryUtils.d.ts.map +1 -1
- package/build/modern/errorBoundaryUtils.js +21 -0
- package/build/modern/errorBoundaryUtils.js.map +1 -1
- package/build/modern/infiniteQueryOptions.cjs.map +1 -1
- package/build/modern/infiniteQueryOptions.d.cts +5 -16
- package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
- package/build/modern/infiniteQueryOptions.d.ts +5 -16
- package/build/modern/infiniteQueryOptions.d.ts.map +1 -1
- package/build/modern/infiniteQueryOptions.js.map +1 -1
- package/build/modern/mutationOptions.cjs.map +1 -1
- package/build/modern/mutationOptions.d.cts +2 -6
- package/build/modern/mutationOptions.d.cts.map +1 -1
- package/build/modern/mutationOptions.d.ts +2 -6
- package/build/modern/mutationOptions.d.ts.map +1 -1
- package/build/modern/mutationOptions.js.map +1 -1
- package/build/modern/queryOptions.cjs.map +1 -1
- package/build/modern/queryOptions.d.cts +6 -16
- package/build/modern/queryOptions.d.cts.map +1 -1
- package/build/modern/queryOptions.d.ts +6 -16
- package/build/modern/queryOptions.d.ts.map +1 -1
- package/build/modern/queryOptions.js.map +1 -1
- package/build/modern/suspense.cjs +27 -0
- package/build/modern/suspense.cjs.map +1 -1
- package/build/modern/suspense.d.cts +27 -0
- package/build/modern/suspense.d.cts.map +1 -1
- package/build/modern/suspense.d.ts +27 -0
- package/build/modern/suspense.d.ts.map +1 -1
- package/build/modern/suspense.js +27 -0
- package/build/modern/suspense.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +2 -22
- package/build/modern/types.d.cts.map +1 -1
- package/build/modern/types.d.ts +2 -22
- package/build/modern/types.d.ts.map +1 -1
- package/build/modern/types.js.map +1 -1
- package/build/modern/useBaseQuery.cjs +13 -0
- package/build/modern/useBaseQuery.cjs.map +1 -1
- package/build/modern/useBaseQuery.d.cts +13 -0
- package/build/modern/useBaseQuery.d.cts.map +1 -1
- package/build/modern/useBaseQuery.d.ts +13 -0
- package/build/modern/useBaseQuery.d.ts.map +1 -1
- package/build/modern/useBaseQuery.js +13 -0
- package/build/modern/useBaseQuery.js.map +1 -1
- package/build/modern/useInfiniteQuery.cjs.map +1 -1
- package/build/modern/useInfiniteQuery.d.cts +12 -21
- package/build/modern/useInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useInfiniteQuery.d.ts +12 -21
- package/build/modern/useInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useInfiniteQuery.js.map +1 -1
- package/build/modern/useIsFetching.cjs +0 -3
- package/build/modern/useIsFetching.cjs.map +1 -1
- package/build/modern/useIsFetching.d.cts +0 -3
- package/build/modern/useIsFetching.d.cts.map +1 -1
- package/build/modern/useIsFetching.d.ts +0 -3
- package/build/modern/useIsFetching.d.ts.map +1 -1
- package/build/modern/useIsFetching.js +0 -3
- package/build/modern/useIsFetching.js.map +1 -1
- package/build/modern/useMutation.cjs +4 -8
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.d.cts +4 -8
- package/build/modern/useMutation.d.cts.map +1 -1
- package/build/modern/useMutation.d.ts +4 -8
- package/build/modern/useMutation.d.ts.map +1 -1
- package/build/modern/useMutation.js +4 -8
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/useMutationState.cjs +13 -12
- package/build/modern/useMutationState.cjs.map +1 -1
- package/build/modern/useMutationState.d.cts +0 -6
- package/build/modern/useMutationState.d.cts.map +1 -1
- package/build/modern/useMutationState.d.ts +0 -6
- package/build/modern/useMutationState.d.ts.map +1 -1
- package/build/modern/useMutationState.js +13 -12
- package/build/modern/useMutationState.js.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.cjs +0 -3
- package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.cts +0 -3
- package/build/modern/usePrefetchInfiniteQuery.d.cts.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.ts +0 -3
- package/build/modern/usePrefetchInfiniteQuery.d.ts.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.js +0 -3
- package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
- package/build/modern/usePrefetchQuery.cjs +0 -3
- package/build/modern/usePrefetchQuery.cjs.map +1 -1
- package/build/modern/usePrefetchQuery.d.cts +0 -3
- package/build/modern/usePrefetchQuery.d.cts.map +1 -1
- package/build/modern/usePrefetchQuery.d.ts +0 -3
- package/build/modern/usePrefetchQuery.d.ts.map +1 -1
- package/build/modern/usePrefetchQuery.js +0 -3
- package/build/modern/usePrefetchQuery.js.map +1 -1
- package/build/modern/useQueries.cjs +7 -8
- package/build/modern/useQueries.cjs.map +1 -1
- package/build/modern/useQueries.d.cts +7 -11
- package/build/modern/useQueries.d.cts.map +1 -1
- package/build/modern/useQueries.d.ts +7 -11
- package/build/modern/useQueries.d.ts.map +1 -1
- package/build/modern/useQueries.js +7 -8
- package/build/modern/useQueries.js.map +1 -1
- package/build/modern/useQuery.cjs.map +1 -1
- package/build/modern/useQuery.d.cts +8 -13
- package/build/modern/useQuery.d.cts.map +1 -1
- package/build/modern/useQuery.d.ts +8 -13
- package/build/modern/useQuery.d.ts.map +1 -1
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.cjs +6 -8
- package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.cts +6 -8
- package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.ts +6 -8
- package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.js +6 -8
- package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/modern/useSuspenseQueries.cjs.map +1 -1
- package/build/modern/useSuspenseQueries.d.cts +0 -9
- package/build/modern/useSuspenseQueries.d.cts.map +1 -1
- package/build/modern/useSuspenseQueries.d.ts +0 -9
- package/build/modern/useSuspenseQueries.d.ts.map +1 -1
- package/build/modern/useSuspenseQueries.js.map +1 -1
- package/build/modern/useSuspenseQuery.cjs +4 -6
- package/build/modern/useSuspenseQuery.cjs.map +1 -1
- package/build/modern/useSuspenseQuery.d.cts +4 -6
- package/build/modern/useSuspenseQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseQuery.d.ts +4 -6
- package/build/modern/useSuspenseQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseQuery.js +4 -6
- package/build/modern/useSuspenseQuery.js.map +1 -1
- package/package.json +10 -8
- package/src/HydrationBoundary.tsx +4 -5
- package/src/IsRestoringProvider.ts +0 -1
- package/src/QueryClientProvider.tsx +3 -4
- package/src/QueryErrorResetBoundary.tsx +30 -6
- package/src/errorBoundaryUtils.ts +21 -0
- package/src/infiniteQueryOptions.ts +5 -16
- package/src/mutationOptions.ts +2 -6
- package/src/queryOptions.ts +8 -17
- package/src/suspense.ts +29 -1
- package/src/types.ts +2 -22
- package/src/useBaseQuery.ts +13 -0
- package/src/useInfiniteQuery.ts +12 -21
- package/src/useIsFetching.ts +0 -3
- package/src/useMutation.ts +4 -8
- package/src/useMutationState.ts +15 -14
- package/src/usePrefetchInfiniteQuery.tsx +0 -3
- package/src/usePrefetchQuery.tsx +0 -3
- package/src/useQueries.ts +7 -11
- package/src/useQuery.ts +8 -13
- package/src/useSuspenseInfiniteQuery.ts +6 -8
- package/src/useSuspenseQueries.ts +0 -9
- package/src/useSuspenseQuery.ts +4 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-query",
|
|
3
|
-
"version": "5.104.
|
|
3
|
+
"version": "5.104.2",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,20 +44,22 @@
|
|
|
44
44
|
"!build/codemods/**/__tests__"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@tanstack/query-core": "5.104.
|
|
47
|
+
"@tanstack/query-core": "5.104.2"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@
|
|
50
|
+
"@eslint-react/eslint-plugin": "^5.23.3",
|
|
51
|
+
"@tanstack/query-persist-client-core": "5.104.2",
|
|
51
52
|
"@tanstack/query-test-utils": "0.0.0",
|
|
52
53
|
"@testing-library/react": "^16.1.0",
|
|
53
54
|
"@testing-library/react-render-stream": "^2.0.2",
|
|
54
55
|
"@types/react": "^19.2.7",
|
|
55
56
|
"@types/react-dom": "^19.2.3",
|
|
56
57
|
"@vitejs/plugin-react": "^6.1.1",
|
|
57
|
-
"
|
|
58
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
58
59
|
"react": "^19.2.1",
|
|
59
60
|
"react-dom": "^19.2.1",
|
|
60
|
-
"react-error-boundary": "^4.1.2"
|
|
61
|
+
"react-error-boundary": "^4.1.2",
|
|
62
|
+
"typescript": "6.0.3"
|
|
61
63
|
},
|
|
62
64
|
"peerDependencies": {
|
|
63
65
|
"react": "^18 || ^19"
|
|
@@ -65,14 +67,14 @@
|
|
|
65
67
|
"scripts": {
|
|
66
68
|
"clean": "premove ./build ./coverage ./dist-ts ./.cache/test-types",
|
|
67
69
|
"compile": "tsc --project tsconfig.json",
|
|
68
|
-
"test:
|
|
70
|
+
"test:oxlint": "oxlint ./src",
|
|
69
71
|
"test:types": "npm-run-all --serial test:types:*",
|
|
70
|
-
"test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts56 --tsBuildInfoFile .cache/test-types/ts56.tsbuildinfo",
|
|
71
72
|
"test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts57 --tsBuildInfoFile .cache/test-types/ts57.tsbuildinfo",
|
|
72
73
|
"test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts58 --tsBuildInfoFile .cache/test-types/ts58.tsbuildinfo",
|
|
73
74
|
"test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts59 --tsBuildInfoFile .cache/test-types/ts59.tsbuildinfo",
|
|
74
75
|
"test:types:tscurrent": "tsc --project tsconfig.json --outDir .cache/test-types/tscurrent --tsBuildInfoFile .cache/test-types/tscurrent.tsbuildinfo",
|
|
75
|
-
"test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --project tsconfig.json --outDir .cache/test-types/ts70 --tsBuildInfoFile .cache/test-types/ts70.tsbuildinfo",
|
|
76
|
+
"test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts70 --tsBuildInfoFile .cache/test-types/ts70.tsbuildinfo",
|
|
77
|
+
"test:types:ts71": "node ../../node_modules/typescript71/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts71 --tsBuildInfoFile .cache/test-types/ts71.tsbuildinfo",
|
|
76
78
|
"test:lib": "vitest",
|
|
77
79
|
"test:lib:dev": "pnpm run test:lib --watch",
|
|
78
80
|
"test:build": "publint --strict && attw --pack",
|
|
@@ -46,11 +46,11 @@ export interface HydrationBoundaryProps {
|
|
|
46
46
|
* update timestamp.
|
|
47
47
|
*
|
|
48
48
|
* Note: Only `queries` can be dehydrated with an `HydrationBoundary`.
|
|
49
|
-
*
|
|
49
|
+
* @param props - The dehydrated `state` to hydrate, the hydrate `options`, an optional custom
|
|
50
|
+
* `queryClient`, and the `children` to render.
|
|
50
51
|
* @returns The provided `children`, rendered unconditionally. New queries in `state` are hydrated into the
|
|
51
52
|
* cache during render; for queries already in the cache, only newer dehydrated data is hydrated, in an effect
|
|
52
53
|
* after commit.
|
|
53
|
-
*
|
|
54
54
|
* @example
|
|
55
55
|
* ```tsx
|
|
56
56
|
* import { HydrationBoundary } from '@tanstack/react-query'
|
|
@@ -59,7 +59,6 @@ export interface HydrationBoundaryProps {
|
|
|
59
59
|
* return <HydrationBoundary state={dehydratedState}>...</HydrationBoundary>
|
|
60
60
|
* }
|
|
61
61
|
* ```
|
|
62
|
-
*
|
|
63
62
|
* @example
|
|
64
63
|
* Server-side prefetch handed off to the client via `dehydrate`:
|
|
65
64
|
* ```tsx
|
|
@@ -122,7 +121,7 @@ export const HydrationBoundary = ({
|
|
|
122
121
|
// State is supplied from the outside and we might as well fail
|
|
123
122
|
// gracefully if it has the wrong shape, so while we type `queries`
|
|
124
123
|
// as required, we still provide a fallback.
|
|
125
|
-
//
|
|
124
|
+
// oxlint-disable-next-line typescript/no-unnecessary-condition
|
|
126
125
|
const queries = state.queries || []
|
|
127
126
|
|
|
128
127
|
const newQueries: DehydratedState['queries'] = []
|
|
@@ -151,7 +150,7 @@ export const HydrationBoundary = ({
|
|
|
151
150
|
if (newQueries.length > 0) {
|
|
152
151
|
// It's actually fine to call this with queries/state that already exists
|
|
153
152
|
// in the cache, or is older. hydrate() is idempotent for queries.
|
|
154
|
-
//
|
|
153
|
+
// oxlint-disable-next-line react-hooks-js/refs
|
|
155
154
|
hydrate(client, { queries: newQueries }, optionsRef.current)
|
|
156
155
|
}
|
|
157
156
|
if (existingQueries.length > 0) {
|
|
@@ -7,7 +7,6 @@ const IsRestoringContext = React.createContext(false)
|
|
|
7
7
|
* If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` hook alongside it to
|
|
8
8
|
* check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid
|
|
9
9
|
* race conditions between the restore and mounting queries.
|
|
10
|
-
*
|
|
11
10
|
* @returns `true` while a persisted client is being restored, `false` otherwise.
|
|
12
11
|
*/
|
|
13
12
|
export const useIsRestoring = () => React.useContext(IsRestoringContext)
|
|
@@ -12,11 +12,11 @@ export const QueryClientContext = React.createContext<QueryClient | undefined>(
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* The `useQueryClient` hook returns the current `QueryClient` instance.
|
|
15
|
-
*
|
|
16
15
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
17
16
|
* be used.
|
|
18
17
|
* @returns The current `QueryClient` instance.
|
|
19
|
-
* @throws If no `queryClient` argument is passed and no `QueryClientProvider` is found in the
|
|
18
|
+
* @throws {Error} If no `queryClient` argument is passed and no `QueryClientProvider` is found in the
|
|
19
|
+
* component tree.
|
|
20
20
|
*/
|
|
21
21
|
export const useQueryClient = (queryClient?: QueryClient) => {
|
|
22
22
|
const client = React.useContext(QueryClientContext)
|
|
@@ -53,9 +53,8 @@ export type QueryClientProviderProps = {
|
|
|
53
53
|
* calls `client.mount()`/`client.unmount()` as this component mounts/unmounts, which subscribes the client to
|
|
54
54
|
* focus/online events (resuming any paused mutations and refetching as needed when the app regains focus or
|
|
55
55
|
* comes back online).
|
|
56
|
-
*
|
|
56
|
+
* @param props - The `client` to provide, and the `children` that get access to it.
|
|
57
57
|
* @returns The provided `children`, wrapped so they can read the `QueryClient` via `useQueryClient`.
|
|
58
|
-
*
|
|
59
58
|
* @example
|
|
60
59
|
* ```tsx
|
|
61
60
|
* import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
@@ -2,18 +2,45 @@
|
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
|
|
4
4
|
// CONTEXT
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Resets any query errors within the boundary, so queries know they can try again.
|
|
8
|
+
*/
|
|
5
9
|
export type QueryErrorResetFunction = () => void
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns whether the boundary has been reset and not yet cleared.
|
|
13
|
+
*/
|
|
6
14
|
export type QueryErrorIsResetFunction = () => boolean
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Clears the reset state, so queries know not to try again until the boundary is reset again.
|
|
18
|
+
*/
|
|
7
19
|
export type QueryErrorClearResetFunction = () => void
|
|
8
20
|
|
|
21
|
+
/**
|
|
22
|
+
* The value a `QueryErrorResetBoundary` shares through context, used to reset query errors within
|
|
23
|
+
* it and to check whether a reset was requested.
|
|
24
|
+
*/
|
|
9
25
|
export interface QueryErrorResetBoundaryValue {
|
|
26
|
+
/**
|
|
27
|
+
* Clears the reset state, so queries know not to try again until the boundary is reset again.
|
|
28
|
+
*/
|
|
10
29
|
clearReset: QueryErrorClearResetFunction
|
|
30
|
+
/**
|
|
31
|
+
* Returns whether the boundary has been reset and not yet cleared.
|
|
32
|
+
*/
|
|
11
33
|
isReset: QueryErrorIsResetFunction
|
|
34
|
+
/**
|
|
35
|
+
* Resets any query errors within the boundary, so queries know they can try again.
|
|
36
|
+
*/
|
|
12
37
|
reset: QueryErrorResetFunction
|
|
13
38
|
}
|
|
14
39
|
|
|
15
40
|
/**
|
|
16
|
-
*
|
|
41
|
+
* Creates the value shared through the boundary's context, which tracks whether a reset was
|
|
42
|
+
* requested.
|
|
43
|
+
* @returns The `clearReset`, `isReset`, and `reset` functions of the boundary.
|
|
17
44
|
*/
|
|
18
45
|
function createValue(): QueryErrorResetBoundaryValue {
|
|
19
46
|
let isReset = false
|
|
@@ -32,6 +59,7 @@ function createValue(): QueryErrorResetBoundaryValue {
|
|
|
32
59
|
},
|
|
33
60
|
/**
|
|
34
61
|
* Returns whether the boundary has been reset and not yet cleared.
|
|
62
|
+
* @returns `true` if the boundary has been reset and not yet cleared.
|
|
35
63
|
*/
|
|
36
64
|
isReset: () => {
|
|
37
65
|
return isReset
|
|
@@ -46,9 +74,7 @@ const QueryErrorResetBoundaryContext = React.createContext(createValue())
|
|
|
46
74
|
/**
|
|
47
75
|
* This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary
|
|
48
76
|
* defined it will reset them globally.
|
|
49
|
-
*
|
|
50
77
|
* @returns The boundary's {@link QueryErrorResetBoundaryValue}.
|
|
51
|
-
*
|
|
52
78
|
* @example
|
|
53
79
|
* ```tsx
|
|
54
80
|
* import { ErrorBoundary } from 'react-error-boundary'
|
|
@@ -80,7 +106,6 @@ export const useQueryErrorResetBoundary = () =>
|
|
|
80
106
|
|
|
81
107
|
/**
|
|
82
108
|
* A render-prop function usable as `children` on `QueryErrorResetBoundary`.
|
|
83
|
-
*
|
|
84
109
|
* @param value - The boundary's {@link QueryErrorResetBoundaryValue}.
|
|
85
110
|
* @returns The children to render.
|
|
86
111
|
*/
|
|
@@ -103,10 +128,9 @@ export interface QueryErrorResetBoundaryProps {
|
|
|
103
128
|
* When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to
|
|
104
129
|
* try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can
|
|
105
130
|
* reset any query errors within the boundaries of the component.
|
|
106
|
-
*
|
|
131
|
+
* @param props - The `children` to render.
|
|
107
132
|
* @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}
|
|
108
133
|
* if `children` is a function.
|
|
109
|
-
*
|
|
110
134
|
* @example
|
|
111
135
|
* ```tsx
|
|
112
136
|
* import { ErrorBoundary } from 'react-error-boundary'
|
|
@@ -10,6 +10,14 @@ import type {
|
|
|
10
10
|
} from '@tanstack/query-core'
|
|
11
11
|
import type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Turns off `retryOnMount` for a query that throws its errors (with `suspense` or `throwOnError`),
|
|
15
|
+
* unless the error boundary has been reset, so a remount doesn't retry the failed query before the
|
|
16
|
+
* user resets the boundary. Mutates the options.
|
|
17
|
+
* @param options - The defaulted query options to adjust.
|
|
18
|
+
* @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
|
|
19
|
+
* @param query - The query, used to evaluate a `throwOnError` function against its error.
|
|
20
|
+
*/
|
|
13
21
|
export const ensurePreventErrorBoundaryRetry = <
|
|
14
22
|
TQueryFnData,
|
|
15
23
|
TError,
|
|
@@ -40,6 +48,11 @@ export const ensurePreventErrorBoundaryRetry = <
|
|
|
40
48
|
}
|
|
41
49
|
}
|
|
42
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Clears the reset state of the error boundary after the component mounts, so later errors are
|
|
53
|
+
* thrown to the boundary again.
|
|
54
|
+
* @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
|
|
55
|
+
*/
|
|
43
56
|
export const useClearResetErrorBoundary = (
|
|
44
57
|
errorResetBoundary: QueryErrorResetBoundaryValue,
|
|
45
58
|
) => {
|
|
@@ -48,6 +61,14 @@ export const useClearResetErrorBoundary = (
|
|
|
48
61
|
}, [errorResetBoundary])
|
|
49
62
|
}
|
|
50
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Checks whether the query error should be thrown to the nearest error boundary: the query errored
|
|
66
|
+
* and isn't fetching, the boundary hasn't been reset, and either `suspense` is enabled with no data
|
|
67
|
+
* or `throwOnError` says so.
|
|
68
|
+
* @param params - The observer `result`, the `errorResetBoundary`, the `throwOnError` option, the
|
|
69
|
+
* `query`, and the `suspense` option.
|
|
70
|
+
* @returns `true` if the error should be thrown.
|
|
71
|
+
*/
|
|
51
72
|
export const getHasError = <
|
|
52
73
|
TData,
|
|
53
74
|
TError,
|
|
@@ -13,7 +13,6 @@ import type { UseInfiniteQueryOptions } from './types'
|
|
|
13
13
|
/**
|
|
14
14
|
* The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set — `data`
|
|
15
15
|
* may be `undefined` while the query is `pending`.
|
|
16
|
-
*
|
|
17
16
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
18
17
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
19
18
|
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
@@ -53,7 +52,6 @@ export type UndefinedInitialDataInfiniteOptions<
|
|
|
53
52
|
* The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set and
|
|
54
53
|
* `queryFn` is not `skipToken` — same as {@link UndefinedInitialDataInfiniteOptions}, but `queryFn` may not be
|
|
55
54
|
* `skipToken`.
|
|
56
|
-
*
|
|
57
55
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
58
56
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
59
57
|
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
@@ -92,7 +90,6 @@ export type UnusedSkipTokenInfiniteOptions<
|
|
|
92
90
|
/**
|
|
93
91
|
* The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is
|
|
94
92
|
* never `undefined` (unless a `select` changes `TData` to include `undefined`).
|
|
95
|
-
*
|
|
96
93
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
97
94
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
98
95
|
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
@@ -132,13 +129,11 @@ export type DefinedInitialDataInfiniteOptions<
|
|
|
132
129
|
* `options.queryKey` is required and is the query key to generate options for.
|
|
133
130
|
*
|
|
134
131
|
* This overload is selected when `initialData` is set.
|
|
135
|
-
*
|
|
136
|
-
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
137
132
|
* @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.
|
|
138
133
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
139
134
|
* @remarks See {@link useInfiniteQuery} for examples that fetch further pages, from a button click or
|
|
140
135
|
* automatically as the user scrolls.
|
|
141
|
-
*
|
|
136
|
+
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
142
137
|
* @example
|
|
143
138
|
* ```tsx
|
|
144
139
|
* import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query'
|
|
@@ -194,11 +189,11 @@ export function infiniteQueryOptions<
|
|
|
194
189
|
* You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
|
|
195
190
|
* These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
|
|
196
191
|
* `options.queryKey` is required and is the query key to generate options for.
|
|
197
|
-
*
|
|
192
|
+
* @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
198
193
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
199
194
|
* @remarks See {@link useInfiniteQuery} for examples that fetch further pages, from a button click or
|
|
200
195
|
* automatically as the user scrolls.
|
|
201
|
-
*
|
|
196
|
+
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
202
197
|
* @example
|
|
203
198
|
* A parameterized factory, so the same options object can be reused per `postId`:
|
|
204
199
|
* ```tsx
|
|
@@ -225,9 +220,6 @@ export function infiniteQueryOptions<
|
|
|
225
220
|
* )
|
|
226
221
|
* }
|
|
227
222
|
* ```
|
|
228
|
-
*
|
|
229
|
-
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
230
|
-
* @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
231
223
|
*/
|
|
232
224
|
export function infiniteQueryOptions<
|
|
233
225
|
TQueryFnData,
|
|
@@ -256,11 +248,11 @@ export function infiniteQueryOptions<
|
|
|
256
248
|
* You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
|
|
257
249
|
* These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
|
|
258
250
|
* `options.queryKey` is required and is the query key to generate options for.
|
|
259
|
-
*
|
|
251
|
+
* @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
260
252
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
261
253
|
* @remarks See {@link useInfiniteQuery} for examples that fetch further pages (from a button click or
|
|
262
254
|
* automatically as the user scrolls) and that use `skipToken` to disable the query until `postId` is set.
|
|
263
|
-
*
|
|
255
|
+
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
264
256
|
* @example
|
|
265
257
|
* A parameterized factory, so the same options object can be reused per `postId`:
|
|
266
258
|
* ```tsx
|
|
@@ -287,9 +279,6 @@ export function infiniteQueryOptions<
|
|
|
287
279
|
* )
|
|
288
280
|
* }
|
|
289
281
|
* ```
|
|
290
|
-
*
|
|
291
|
-
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
292
|
-
* @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
293
282
|
*/
|
|
294
283
|
export function infiniteQueryOptions<
|
|
295
284
|
TQueryFnData,
|
package/src/mutationOptions.ts
CHANGED
|
@@ -5,12 +5,10 @@ import type { UseMutationOptions } from './types'
|
|
|
5
5
|
* You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. A
|
|
6
6
|
* `mutationKey` is required on this overload so the mutation can be looked up later, e.g. with
|
|
7
7
|
* `useMutationState`.
|
|
8
|
-
*
|
|
9
|
-
* @see {@link useMutation} to run the mutation these options describe.
|
|
10
8
|
* @param options - The mutation options to use, identical to what you'd pass to `useMutation`, with a
|
|
11
9
|
* required `mutationKey`.
|
|
12
10
|
* @returns The same options object, unchanged.
|
|
13
|
-
*
|
|
11
|
+
* @see {@link useMutation} to run the mutation these options describe.
|
|
14
12
|
* @example
|
|
15
13
|
* Looking the mutation up elsewhere via its `mutationKey`, e.g. for a global "saving…" indicator:
|
|
16
14
|
* ```tsx
|
|
@@ -49,13 +47,11 @@ export function mutationOptions<
|
|
|
49
47
|
* `mutationKey` is required on this overload — use this when you don't need to target the mutation via a
|
|
50
48
|
* `mutationKey` filter later (e.g. with `useMutationState`); it can still be observed through other filters,
|
|
51
49
|
* such as `status`.
|
|
52
|
-
*
|
|
53
|
-
* @see {@link useMutation} to run the mutation these options describe.
|
|
54
50
|
* @param options - The mutation options to use, identical to what you'd pass to `useMutation`, without a
|
|
55
51
|
* `mutationKey`.
|
|
56
52
|
* @returns The same options object, unchanged.
|
|
57
53
|
* @remarks See the other overload's example for looking a mutation up via `useMutationState`.
|
|
58
|
-
*
|
|
54
|
+
* @see {@link useMutation} to run the mutation these options describe.
|
|
59
55
|
* @example
|
|
60
56
|
* ```tsx
|
|
61
57
|
* import { mutationOptions, useMutation } from '@tanstack/react-query'
|
package/src/queryOptions.ts
CHANGED
|
@@ -13,7 +13,6 @@ import type { UseQueryOptions } from './types'
|
|
|
13
13
|
/**
|
|
14
14
|
* The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be
|
|
15
15
|
* `undefined` while the query is `pending`.
|
|
16
|
-
*
|
|
17
16
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
18
17
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
19
18
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
@@ -41,7 +40,6 @@ export type UndefinedInitialDataOptions<
|
|
|
41
40
|
/**
|
|
42
41
|
* The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is
|
|
43
42
|
* not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.
|
|
44
|
-
*
|
|
45
43
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
46
44
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
47
45
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
@@ -71,7 +69,6 @@ export type UnusedSkipTokenOptions<
|
|
|
71
69
|
/**
|
|
72
70
|
* The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never
|
|
73
71
|
* `undefined` (unless a `select` changes `TData` to include `undefined`).
|
|
74
|
-
*
|
|
75
72
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
76
73
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
77
74
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
@@ -91,7 +88,8 @@ export type DefinedInitialDataOptions<
|
|
|
91
88
|
* cache.
|
|
92
89
|
*/
|
|
93
90
|
initialData:
|
|
94
|
-
|
|
91
|
+
| NonUndefinedGuard<TQueryFnData>
|
|
92
|
+
| (() => NonUndefinedGuard<TQueryFnData>)
|
|
95
93
|
/**
|
|
96
94
|
* Optional here, but omitting it is only safe when no fetch will be attempted — for example with
|
|
97
95
|
* `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no
|
|
@@ -107,12 +105,10 @@ export type DefinedInitialDataOptions<
|
|
|
107
105
|
*
|
|
108
106
|
* This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless
|
|
109
107
|
* a `select` changes `TData` to include `undefined`).
|
|
110
|
-
*
|
|
111
|
-
* @see {@link useQuery} to run a query with these options.
|
|
112
|
-
* @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
|
|
113
108
|
* @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
|
|
114
109
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
115
|
-
*
|
|
110
|
+
* @see {@link useQuery} to run a query with these options.
|
|
111
|
+
* @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
|
|
116
112
|
* @example
|
|
117
113
|
* ```tsx
|
|
118
114
|
* import { queryOptions, useQuery } from '@tanstack/react-query'
|
|
@@ -153,12 +149,10 @@ export function queryOptions<
|
|
|
153
149
|
* You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
|
|
154
150
|
* be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
|
|
155
151
|
* is the query key to generate options for.
|
|
156
|
-
*
|
|
157
|
-
* @see {@link useQuery} to run a query with these options.
|
|
158
|
-
* @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
|
|
159
152
|
* @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `useQuery`.
|
|
160
153
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
161
|
-
*
|
|
154
|
+
* @see {@link useQuery} to run a query with these options.
|
|
155
|
+
* @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
|
|
162
156
|
* @example
|
|
163
157
|
* A parameterized factory, so the same options object can be reused per `id`:
|
|
164
158
|
* ```tsx
|
|
@@ -194,13 +188,11 @@ export function queryOptions<
|
|
|
194
188
|
* You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
|
|
195
189
|
* be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
|
|
196
190
|
* is the query key to generate options for.
|
|
197
|
-
*
|
|
198
|
-
* @see {@link useQuery} to run a query with these options.
|
|
199
|
-
* @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
|
|
200
191
|
* @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.
|
|
201
192
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
202
193
|
* @remarks This is the only overload that accepts `queryFn: skipToken`, shown below.
|
|
203
|
-
*
|
|
194
|
+
* @see {@link useQuery} to run a query with these options.
|
|
195
|
+
* @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
|
|
204
196
|
* @example
|
|
205
197
|
* A parameterized factory, so the same options object can be reused per `id`:
|
|
206
198
|
* ```tsx
|
|
@@ -221,7 +213,6 @@ export function queryOptions<
|
|
|
221
213
|
* return <h1>{data.title}</h1>
|
|
222
214
|
* }
|
|
223
215
|
* ```
|
|
224
|
-
*
|
|
225
216
|
* @example
|
|
226
217
|
* A factory that disables the query, type safe, until `postId` is set:
|
|
227
218
|
* ```tsx
|
package/src/suspense.ts
CHANGED
|
@@ -8,6 +8,13 @@ import type {
|
|
|
8
8
|
} from '@tanstack/query-core'
|
|
9
9
|
import type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* The default `throwOnError` of the suspense hooks: throws the error to the nearest error boundary
|
|
13
|
+
* only if the query has no data to show.
|
|
14
|
+
* @param _error - The error of the query. Unused.
|
|
15
|
+
* @param query - The query that errored.
|
|
16
|
+
* @returns `true` if the query has no data.
|
|
17
|
+
*/
|
|
11
18
|
export const defaultThrowOnError = <
|
|
12
19
|
TQueryFnData = unknown,
|
|
13
20
|
TError = DefaultError,
|
|
@@ -18,6 +25,12 @@ export const defaultThrowOnError = <
|
|
|
18
25
|
query: Query<TQueryFnData, TError, TData, TQueryKey>,
|
|
19
26
|
) => query.state.data === undefined
|
|
20
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Raises `staleTime` and a numeric `gcTime` to at least 1000ms when `suspense` is enabled, so a
|
|
30
|
+
* component that remounts after suspending doesn't refetch right away or find the query garbage
|
|
31
|
+
* collected. A `'static'` `staleTime` is kept as is. Mutates the options.
|
|
32
|
+
* @param defaultedOptions - The defaulted query options to adjust.
|
|
33
|
+
*/
|
|
21
34
|
export const ensureSuspenseTimers = (
|
|
22
35
|
defaultedOptions: DefaultedQueryObserverOptions<any, any, any, any, any>,
|
|
23
36
|
) => {
|
|
@@ -46,12 +59,27 @@ export const ensureSuspenseTimers = (
|
|
|
46
59
|
}
|
|
47
60
|
}
|
|
48
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Checks whether a query should suspend: `suspense` is enabled and the result is still `pending`.
|
|
64
|
+
* @param defaultedOptions - The defaulted query options, if any.
|
|
65
|
+
* @param result - The current result of the observer.
|
|
66
|
+
* @returns `true` if the component should suspend.
|
|
67
|
+
*/
|
|
49
68
|
export const shouldSuspend = (
|
|
50
69
|
defaultedOptions:
|
|
51
|
-
DefaultedQueryObserverOptions<any, any, any, any, any>
|
|
70
|
+
| DefaultedQueryObserverOptions<any, any, any, any, any>
|
|
71
|
+
| undefined,
|
|
52
72
|
result: QueryObserverResult<any, any>,
|
|
53
73
|
) => defaultedOptions?.suspense && result.isPending
|
|
54
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Fetches the query for a suspending component, without affecting the observer's own result. If
|
|
77
|
+
* the fetch fails, the reset state of the error boundary is cleared, so the error is thrown to it.
|
|
78
|
+
* @param defaultedOptions - The defaulted query options to fetch with.
|
|
79
|
+
* @param observer - The observer of the query.
|
|
80
|
+
* @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
|
|
81
|
+
* @returns A promise that resolves once the fetch settles. It never rejects.
|
|
82
|
+
*/
|
|
55
83
|
export const fetchOptimistic = <
|
|
56
84
|
TQueryFnData,
|
|
57
85
|
TError,
|