@tanstack/react-query 4.35.7 → 4.39.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.
Files changed (146) hide show
  1. package/build/lib/__tests__/queryOptions.types.test.d.ts +2 -0
  2. package/build/lib/__tests__/useSuspenseQueries.types.test.d.ts +6 -0
  3. package/build/lib/__tests__/useSuspenseQuery.types.test.d.ts +2 -0
  4. package/build/lib/__tests__/utils.d.ts +1 -0
  5. package/build/lib/index.d.ts +3 -0
  6. package/build/lib/queryOptions.d.ts +14 -0
  7. package/build/lib/useQueries.d.ts +22 -11
  8. package/build/lib/useQuery.d.ts +21 -14
  9. package/build/lib/useSuspenseQueries.d.ts +66 -0
  10. package/build/lib/useSuspenseQuery.d.ts +8 -0
  11. package/package.json +3 -10
  12. package/src/__tests__/queryOptions.types.test.tsx +270 -0
  13. package/src/__tests__/useQuery.types.test.tsx +1 -2
  14. package/src/__tests__/useSuspenseQueries.types.test.tsx +102 -0
  15. package/src/__tests__/useSuspenseQuery.types.test.tsx +81 -0
  16. package/src/__tests__/utils.tsx +2 -0
  17. package/src/index.ts +3 -0
  18. package/src/queryOptions.ts +86 -0
  19. package/src/useQueries.ts +50 -22
  20. package/src/useQuery.ts +55 -22
  21. package/src/useSuspenseQueries.ts +162 -0
  22. package/src/useSuspenseQuery.ts +58 -0
  23. package/build/lib/Hydrate.esm.js +0 -32
  24. package/build/lib/Hydrate.esm.js.map +0 -1
  25. package/build/lib/Hydrate.js +0 -57
  26. package/build/lib/Hydrate.js.map +0 -1
  27. package/build/lib/Hydrate.mjs +0 -32
  28. package/build/lib/Hydrate.mjs.map +0 -1
  29. package/build/lib/QueryClientProvider.esm.js +0 -66
  30. package/build/lib/QueryClientProvider.esm.js.map +0 -1
  31. package/build/lib/QueryClientProvider.js +0 -92
  32. package/build/lib/QueryClientProvider.js.map +0 -1
  33. package/build/lib/QueryClientProvider.mjs +0 -66
  34. package/build/lib/QueryClientProvider.mjs.map +0 -1
  35. package/build/lib/QueryErrorResetBoundary.esm.js +0 -33
  36. package/build/lib/QueryErrorResetBoundary.esm.js.map +0 -1
  37. package/build/lib/QueryErrorResetBoundary.js +0 -58
  38. package/build/lib/QueryErrorResetBoundary.js.map +0 -1
  39. package/build/lib/QueryErrorResetBoundary.mjs +0 -33
  40. package/build/lib/QueryErrorResetBoundary.mjs.map +0 -1
  41. package/build/lib/errorBoundaryUtils.esm.js +0 -28
  42. package/build/lib/errorBoundaryUtils.esm.js.map +0 -1
  43. package/build/lib/errorBoundaryUtils.js +0 -54
  44. package/build/lib/errorBoundaryUtils.js.map +0 -1
  45. package/build/lib/errorBoundaryUtils.mjs +0 -28
  46. package/build/lib/errorBoundaryUtils.mjs.map +0 -1
  47. package/build/lib/index.esm.js +0 -13
  48. package/build/lib/index.esm.js.map +0 -1
  49. package/build/lib/index.js +0 -41
  50. package/build/lib/index.js.map +0 -1
  51. package/build/lib/index.mjs +0 -13
  52. package/build/lib/index.mjs.map +0 -1
  53. package/build/lib/isRestoring.esm.js +0 -9
  54. package/build/lib/isRestoring.esm.js.map +0 -1
  55. package/build/lib/isRestoring.js +0 -34
  56. package/build/lib/isRestoring.js.map +0 -1
  57. package/build/lib/isRestoring.mjs +0 -9
  58. package/build/lib/isRestoring.mjs.map +0 -1
  59. package/build/lib/reactBatchedUpdates.esm.js +0 -7
  60. package/build/lib/reactBatchedUpdates.esm.js.map +0 -1
  61. package/build/lib/reactBatchedUpdates.js +0 -31
  62. package/build/lib/reactBatchedUpdates.js.map +0 -1
  63. package/build/lib/reactBatchedUpdates.mjs +0 -7
  64. package/build/lib/reactBatchedUpdates.mjs.map +0 -1
  65. package/build/lib/reactBatchedUpdates.native.esm.js +0 -2
  66. package/build/lib/reactBatchedUpdates.native.esm.js.map +0 -1
  67. package/build/lib/reactBatchedUpdates.native.js +0 -13
  68. package/build/lib/reactBatchedUpdates.native.js.map +0 -1
  69. package/build/lib/reactBatchedUpdates.native.mjs +0 -2
  70. package/build/lib/reactBatchedUpdates.native.mjs.map +0 -1
  71. package/build/lib/setBatchUpdatesFn.esm.js +0 -5
  72. package/build/lib/setBatchUpdatesFn.esm.js.map +0 -1
  73. package/build/lib/setBatchUpdatesFn.js +0 -7
  74. package/build/lib/setBatchUpdatesFn.js.map +0 -1
  75. package/build/lib/setBatchUpdatesFn.mjs +0 -5
  76. package/build/lib/setBatchUpdatesFn.mjs.map +0 -1
  77. package/build/lib/suspense.esm.js +0 -24
  78. package/build/lib/suspense.esm.js.map +0 -1
  79. package/build/lib/suspense.js +0 -31
  80. package/build/lib/suspense.js.map +0 -1
  81. package/build/lib/suspense.mjs +0 -24
  82. package/build/lib/suspense.mjs.map +0 -1
  83. package/build/lib/useBaseQuery.esm.js +0 -72
  84. package/build/lib/useBaseQuery.esm.js.map +0 -1
  85. package/build/lib/useBaseQuery.js +0 -96
  86. package/build/lib/useBaseQuery.js.map +0 -1
  87. package/build/lib/useBaseQuery.mjs +0 -72
  88. package/build/lib/useBaseQuery.mjs.map +0 -1
  89. package/build/lib/useInfiniteQuery.esm.js +0 -11
  90. package/build/lib/useInfiniteQuery.esm.js.map +0 -1
  91. package/build/lib/useInfiniteQuery.js +0 -15
  92. package/build/lib/useInfiniteQuery.js.map +0 -1
  93. package/build/lib/useInfiniteQuery.mjs +0 -11
  94. package/build/lib/useInfiniteQuery.mjs.map +0 -1
  95. package/build/lib/useIsFetching.esm.js +0 -17
  96. package/build/lib/useIsFetching.esm.js.map +0 -1
  97. package/build/lib/useIsFetching.js +0 -41
  98. package/build/lib/useIsFetching.js.map +0 -1
  99. package/build/lib/useIsFetching.mjs +0 -17
  100. package/build/lib/useIsFetching.mjs.map +0 -1
  101. package/build/lib/useIsMutating.esm.js +0 -17
  102. package/build/lib/useIsMutating.esm.js.map +0 -1
  103. package/build/lib/useIsMutating.js +0 -41
  104. package/build/lib/useIsMutating.js.map +0 -1
  105. package/build/lib/useIsMutating.mjs +0 -17
  106. package/build/lib/useIsMutating.mjs.map +0 -1
  107. package/build/lib/useMutation.esm.js +0 -35
  108. package/build/lib/useMutation.esm.js.map +0 -1
  109. package/build/lib/useMutation.js +0 -59
  110. package/build/lib/useMutation.js.map +0 -1
  111. package/build/lib/useMutation.mjs +0 -35
  112. package/build/lib/useMutation.mjs.map +0 -1
  113. package/build/lib/useQueries.esm.js +0 -81
  114. package/build/lib/useQueries.esm.js.map +0 -1
  115. package/build/lib/useQueries.js +0 -105
  116. package/build/lib/useQueries.js.map +0 -1
  117. package/build/lib/useQueries.mjs +0 -81
  118. package/build/lib/useQueries.mjs.map +0 -1
  119. package/build/lib/useQuery.esm.js +0 -11
  120. package/build/lib/useQuery.esm.js.map +0 -1
  121. package/build/lib/useQuery.js +0 -15
  122. package/build/lib/useQuery.js.map +0 -1
  123. package/build/lib/useQuery.mjs +0 -11
  124. package/build/lib/useQuery.mjs.map +0 -1
  125. package/build/lib/useSyncExternalStore.esm.js +0 -7
  126. package/build/lib/useSyncExternalStore.esm.js.map +0 -1
  127. package/build/lib/useSyncExternalStore.js +0 -11
  128. package/build/lib/useSyncExternalStore.js.map +0 -1
  129. package/build/lib/useSyncExternalStore.mjs +0 -7
  130. package/build/lib/useSyncExternalStore.mjs.map +0 -1
  131. package/build/lib/useSyncExternalStore.native.esm.js +0 -2
  132. package/build/lib/useSyncExternalStore.native.esm.js.map +0 -1
  133. package/build/lib/useSyncExternalStore.native.js +0 -13
  134. package/build/lib/useSyncExternalStore.native.js.map +0 -1
  135. package/build/lib/useSyncExternalStore.native.mjs +0 -2
  136. package/build/lib/useSyncExternalStore.native.mjs.map +0 -1
  137. package/build/lib/utils.esm.js +0 -11
  138. package/build/lib/utils.esm.js.map +0 -1
  139. package/build/lib/utils.js +0 -15
  140. package/build/lib/utils.js.map +0 -1
  141. package/build/lib/utils.mjs +0 -11
  142. package/build/lib/utils.mjs.map +0 -1
  143. package/build/umd/index.development.js +0 -3961
  144. package/build/umd/index.development.js.map +0 -1
  145. package/build/umd/index.production.js +0 -2
  146. package/build/umd/index.production.js.map +0 -1
@@ -0,0 +1,162 @@
1
+ import { useQueries } from './useQueries'
2
+ import type { UseQueryOptions } from './types'
3
+ import type { NetworkMode, QueryFunction } from '@tanstack/query-core'
4
+ import type {
5
+ UseSuspenseQueryOptions,
6
+ UseSuspenseQueryResult,
7
+ } from './useSuspenseQuery'
8
+
9
+ // Avoid TS depth-limit error in case of large array literal
10
+ type MAXIMUM_DEPTH = 20
11
+
12
+ type GetSuspenseOptions<T> =
13
+ // Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }
14
+ T extends {
15
+ queryFnData: infer TQueryFnData
16
+ error?: infer TError
17
+ data: infer TData
18
+ }
19
+ ? UseSuspenseQueryOptions<TQueryFnData, TError, TData>
20
+ : T extends { queryFnData: infer TQueryFnData; error?: infer TError }
21
+ ? UseSuspenseQueryOptions<TQueryFnData, TError>
22
+ : T extends { data: infer TData; error?: infer TError }
23
+ ? UseSuspenseQueryOptions<unknown, TError, TData>
24
+ : // Part 2: responsible for applying explicit type parameter to function arguments, if tuple [TQueryFnData, TError, TData]
25
+ T extends [infer TQueryFnData, infer TError, infer TData]
26
+ ? UseSuspenseQueryOptions<TQueryFnData, TError, TData>
27
+ : T extends [infer TQueryFnData, infer TError]
28
+ ? UseSuspenseQueryOptions<TQueryFnData, TError>
29
+ : T extends [infer TQueryFnData]
30
+ ? UseSuspenseQueryOptions<TQueryFnData>
31
+ : // Part 3: responsible for inferring and enforcing type if no explicit parameter was provided
32
+ T extends {
33
+ queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey>
34
+ select?: (data: any) => infer TData
35
+ }
36
+ ? UseSuspenseQueryOptions<TQueryFnData, unknown, TData, TQueryKey>
37
+ : T extends {
38
+ queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey>
39
+ }
40
+ ? UseSuspenseQueryOptions<TQueryFnData, unknown, TQueryFnData, TQueryKey>
41
+ : // Fallback
42
+ UseSuspenseQueryOptions
43
+
44
+ type GetSuspenseResults<T> =
45
+ // Part 1: responsible for mapping explicit type parameter to function result, if object
46
+ T extends { queryFnData: any; error?: infer TError; data: infer TData }
47
+ ? UseSuspenseQueryResult<TData, TError>
48
+ : T extends { queryFnData: infer TQueryFnData; error?: infer TError }
49
+ ? UseSuspenseQueryResult<TQueryFnData, TError>
50
+ : T extends { data: infer TData; error?: infer TError }
51
+ ? UseSuspenseQueryResult<TData, TError>
52
+ : // Part 2: responsible for mapping explicit type parameter to function result, if tuple
53
+ T extends [any, infer TError, infer TData]
54
+ ? UseSuspenseQueryResult<TData, TError>
55
+ : T extends [infer TQueryFnData, infer TError]
56
+ ? UseSuspenseQueryResult<TQueryFnData, TError>
57
+ : T extends [infer TQueryFnData]
58
+ ? UseSuspenseQueryResult<TQueryFnData>
59
+ : // Part 3: responsible for mapping inferred type to results, if no explicit parameter was provided
60
+ T extends {
61
+ queryFn?: QueryFunction<infer TQueryFnData, any>
62
+ select?: (data: any) => infer TData
63
+ }
64
+ ? UseSuspenseQueryResult<unknown extends TData ? TQueryFnData : TData>
65
+ : T extends {
66
+ queryFn?: QueryFunction<infer TQueryFnData, any>
67
+ }
68
+ ? UseSuspenseQueryResult<TQueryFnData>
69
+ : // Fallback
70
+ UseSuspenseQueryResult
71
+
72
+ /**
73
+ * SuspenseQueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
74
+ */
75
+ export type SuspenseQueriesOptions<
76
+ T extends Array<any>,
77
+ TResult extends Array<any> = [],
78
+ TDepth extends ReadonlyArray<number> = [],
79
+ > = TDepth['length'] extends MAXIMUM_DEPTH
80
+ ? Array<UseSuspenseQueryOptions>
81
+ : T extends []
82
+ ? []
83
+ : T extends [infer Head]
84
+ ? [...TResult, GetSuspenseOptions<Head>]
85
+ : T extends [infer Head, ...infer Tail]
86
+ ? SuspenseQueriesOptions<
87
+ [...Tail],
88
+ [...TResult, GetSuspenseOptions<Head>],
89
+ [...TDepth, 1]
90
+ >
91
+ : Array<unknown> extends T
92
+ ? T
93
+ : // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogenous type!
94
+ // use this to infer the param types in the case of Array.map() argument
95
+ T extends Array<
96
+ UseSuspenseQueryOptions<
97
+ infer TQueryFnData,
98
+ infer TError,
99
+ infer TData,
100
+ infer TQueryKey
101
+ >
102
+ >
103
+ ? Array<UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>>
104
+ : // Fallback
105
+ Array<UseSuspenseQueryOptions>
106
+
107
+ /**
108
+ * SuspenseQueriesResults reducer recursively maps type param to results
109
+ */
110
+ export type SuspenseQueriesResults<
111
+ T extends Array<any>,
112
+ TResult extends Array<any> = [],
113
+ TDepth extends ReadonlyArray<number> = [],
114
+ > = TDepth['length'] extends MAXIMUM_DEPTH
115
+ ? Array<UseSuspenseQueryResult>
116
+ : T extends []
117
+ ? []
118
+ : T extends [infer Head]
119
+ ? [...TResult, GetSuspenseResults<Head>]
120
+ : T extends [infer Head, ...infer Tail]
121
+ ? SuspenseQueriesResults<
122
+ [...Tail],
123
+ [...TResult, GetSuspenseResults<Head>],
124
+ [...TDepth, 1]
125
+ >
126
+ : T extends Array<
127
+ UseSuspenseQueryOptions<
128
+ infer TQueryFnData,
129
+ infer TError,
130
+ infer TData,
131
+ any
132
+ >
133
+ >
134
+ ? // Dynamic-size (homogenous) UseQueryOptions array: map directly to array of results
135
+ Array<
136
+ UseSuspenseQueryResult<
137
+ unknown extends TData ? TQueryFnData : TData,
138
+ TError
139
+ >
140
+ >
141
+ : // Fallback
142
+ Array<UseSuspenseQueryResult>
143
+
144
+ export function useSuspenseQueries<T extends any[]>({
145
+ queries,
146
+ context,
147
+ }: {
148
+ queries: readonly [...SuspenseQueriesOptions<T>]
149
+ context?: UseQueryOptions['context']
150
+ }): SuspenseQueriesResults<T> {
151
+ return useQueries({
152
+ queries: queries.map((query) => ({
153
+ ...query,
154
+ enabled: true,
155
+ useErrorBoundary: true,
156
+ suspense: true,
157
+ placeholderData: undefined,
158
+ networkMode: 'always' as NetworkMode,
159
+ })),
160
+ context,
161
+ }) as SuspenseQueriesResults<T>
162
+ }
@@ -0,0 +1,58 @@
1
+ import { QueryObserver } from '@tanstack/query-core'
2
+ import { useBaseQuery } from './useBaseQuery'
3
+ import type {
4
+ DefinedQueryObserverResult,
5
+ OmitKeyof,
6
+ QueryKey,
7
+ } from '@tanstack/query-core'
8
+ import type { UseQueryOptions } from './types'
9
+
10
+ type DistributiveOmit<TObject, TKey extends keyof TObject> = TObject extends any
11
+ ? Omit<TObject, TKey>
12
+ : never
13
+
14
+ export type UseSuspenseQueryResult<
15
+ TData = unknown,
16
+ TError = unknown,
17
+ > = DistributiveOmit<
18
+ DefinedQueryObserverResult<TData, TError>,
19
+ 'isPlaceholderData'
20
+ >
21
+
22
+ export type UseSuspenseQueryOptions<
23
+ TQueryFnData = unknown,
24
+ TError = unknown,
25
+ TData = TQueryFnData,
26
+ TQueryKey extends QueryKey = QueryKey,
27
+ > = OmitKeyof<
28
+ UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
29
+ | 'enabled'
30
+ | 'useErrorBoundary'
31
+ | 'suspense'
32
+ | 'placeholderData'
33
+ | 'networkMode'
34
+ | 'onSuccess'
35
+ | 'onError'
36
+ | 'onSettled'
37
+ | 'getPreviousPageParam'
38
+ | 'getNextPageParam'
39
+ >
40
+
41
+ export function useSuspenseQuery<
42
+ TQueryFnData = unknown,
43
+ TError = unknown,
44
+ TData = TQueryFnData,
45
+ TQueryKey extends QueryKey = QueryKey,
46
+ >(options: UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>) {
47
+ return useBaseQuery(
48
+ {
49
+ ...options,
50
+ enabled: true,
51
+ useErrorBoundary: true,
52
+ suspense: true,
53
+ placeholderData: undefined,
54
+ networkMode: 'always',
55
+ },
56
+ QueryObserver,
57
+ ) as UseSuspenseQueryResult<TData, TError>
58
+ }
@@ -1,32 +0,0 @@
1
- 'use client';
2
- import * as React from 'react';
3
- import { hydrate } from '@tanstack/query-core';
4
- import { useQueryClient } from './QueryClientProvider.esm.js';
5
-
6
- function useHydrate(state, options = {}) {
7
- const queryClient = useQueryClient({
8
- context: options.context
9
- });
10
- const optionsRef = React.useRef(options);
11
- optionsRef.current = options; // Running hydrate again with the same queries is safe,
12
- // it wont overwrite or initialize existing queries,
13
- // relying on useMemo here is only a performance optimization.
14
- // hydrate can and should be run *during* render here for SSR to work properly
15
-
16
- React.useMemo(() => {
17
- if (state) {
18
- hydrate(queryClient, state, optionsRef.current);
19
- }
20
- }, [queryClient, state]);
21
- }
22
- const Hydrate = ({
23
- children,
24
- options,
25
- state
26
- }) => {
27
- useHydrate(state, options);
28
- return children;
29
- };
30
-
31
- export { Hydrate, useHydrate };
32
- //# sourceMappingURL=Hydrate.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Hydrate.esm.js","sources":["../../src/Hydrate.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport { hydrate } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport type { HydrateOptions } from '@tanstack/query-core'\nimport type { ContextOptions } from './types'\n\nexport function useHydrate(\n state: unknown,\n options: HydrateOptions & ContextOptions = {},\n) {\n const queryClient = useQueryClient({ context: options.context })\n\n const optionsRef = React.useRef(options)\n optionsRef.current = options\n\n // Running hydrate again with the same queries is safe,\n // it wont overwrite or initialize existing queries,\n // relying on useMemo here is only a performance optimization.\n // hydrate can and should be run *during* render here for SSR to work properly\n React.useMemo(() => {\n if (state) {\n hydrate(queryClient, state, optionsRef.current)\n }\n }, [queryClient, state])\n}\n\nexport interface HydrateProps {\n state?: unknown\n options?: HydrateOptions\n children?: React.ReactNode\n}\n\nexport const Hydrate = ({ children, options, state }: HydrateProps) => {\n useHydrate(state, options)\n return children as React.ReactElement\n}\n"],"names":["optionsRef","state","useHydrate"],"mappings":";;;;;AAQO;;;AAI8B;AAEnC;AACAA;AAGA;AACA;AACA;;;AAEE;;AAEC;AACF;AACF;AAQM;;;AAAsCC;AAArB;AACtBC;AACA;AACD;;"}
@@ -1,57 +0,0 @@
1
- 'use client';
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var React = require('react');
7
- var queryCore = require('@tanstack/query-core');
8
- var QueryClientProvider = require('./QueryClientProvider.js');
9
-
10
- function _interopNamespace(e) {
11
- if (e && e.__esModule) return e;
12
- var n = Object.create(null);
13
- if (e) {
14
- Object.keys(e).forEach(function (k) {
15
- if (k !== 'default') {
16
- var d = Object.getOwnPropertyDescriptor(e, k);
17
- Object.defineProperty(n, k, d.get ? d : {
18
- enumerable: true,
19
- get: function () { return e[k]; }
20
- });
21
- }
22
- });
23
- }
24
- n["default"] = e;
25
- return Object.freeze(n);
26
- }
27
-
28
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
29
-
30
- function useHydrate(state, options = {}) {
31
- const queryClient = QueryClientProvider.useQueryClient({
32
- context: options.context
33
- });
34
- const optionsRef = React__namespace.useRef(options);
35
- optionsRef.current = options; // Running hydrate again with the same queries is safe,
36
- // it wont overwrite or initialize existing queries,
37
- // relying on useMemo here is only a performance optimization.
38
- // hydrate can and should be run *during* render here for SSR to work properly
39
-
40
- React__namespace.useMemo(() => {
41
- if (state) {
42
- queryCore.hydrate(queryClient, state, optionsRef.current);
43
- }
44
- }, [queryClient, state]);
45
- }
46
- const Hydrate = ({
47
- children,
48
- options,
49
- state
50
- }) => {
51
- useHydrate(state, options);
52
- return children;
53
- };
54
-
55
- exports.Hydrate = Hydrate;
56
- exports.useHydrate = useHydrate;
57
- //# sourceMappingURL=Hydrate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Hydrate.js","sources":["../../src/Hydrate.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport { hydrate } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport type { HydrateOptions } from '@tanstack/query-core'\nimport type { ContextOptions } from './types'\n\nexport function useHydrate(\n state: unknown,\n options: HydrateOptions & ContextOptions = {},\n) {\n const queryClient = useQueryClient({ context: options.context })\n\n const optionsRef = React.useRef(options)\n optionsRef.current = options\n\n // Running hydrate again with the same queries is safe,\n // it wont overwrite or initialize existing queries,\n // relying on useMemo here is only a performance optimization.\n // hydrate can and should be run *during* render here for SSR to work properly\n React.useMemo(() => {\n if (state) {\n hydrate(queryClient, state, optionsRef.current)\n }\n }, [queryClient, state])\n}\n\nexport interface HydrateProps {\n state?: unknown\n options?: HydrateOptions\n children?: React.ReactNode\n}\n\nexport const Hydrate = ({ children, options, state }: HydrateProps) => {\n useHydrate(state, options)\n return children as React.ReactElement\n}\n"],"names":["optionsRef","state","useHydrate"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQO;;;AAI8B;AAEnC;AACAA;AAGA;AACA;AACA;;;AAEE;;AAEC;AACF;AACF;AAQM;;;AAAsCC;AAArB;AACtBC;AACA;AACD;;;"}
@@ -1,32 +0,0 @@
1
- 'use client';
2
- import * as React from 'react';
3
- import { hydrate } from '@tanstack/query-core';
4
- import { useQueryClient } from './QueryClientProvider.mjs';
5
-
6
- function useHydrate(state, options = {}) {
7
- const queryClient = useQueryClient({
8
- context: options.context
9
- });
10
- const optionsRef = React.useRef(options);
11
- optionsRef.current = options; // Running hydrate again with the same queries is safe,
12
- // it wont overwrite or initialize existing queries,
13
- // relying on useMemo here is only a performance optimization.
14
- // hydrate can and should be run *during* render here for SSR to work properly
15
-
16
- React.useMemo(() => {
17
- if (state) {
18
- hydrate(queryClient, state, optionsRef.current);
19
- }
20
- }, [queryClient, state]);
21
- }
22
- const Hydrate = ({
23
- children,
24
- options,
25
- state
26
- }) => {
27
- useHydrate(state, options);
28
- return children;
29
- };
30
-
31
- export { Hydrate, useHydrate };
32
- //# sourceMappingURL=Hydrate.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Hydrate.mjs","sources":["../../src/Hydrate.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport { hydrate } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport type { HydrateOptions } from '@tanstack/query-core'\nimport type { ContextOptions } from './types'\n\nexport function useHydrate(\n state: unknown,\n options: HydrateOptions & ContextOptions = {},\n) {\n const queryClient = useQueryClient({ context: options.context })\n\n const optionsRef = React.useRef(options)\n optionsRef.current = options\n\n // Running hydrate again with the same queries is safe,\n // it wont overwrite or initialize existing queries,\n // relying on useMemo here is only a performance optimization.\n // hydrate can and should be run *during* render here for SSR to work properly\n React.useMemo(() => {\n if (state) {\n hydrate(queryClient, state, optionsRef.current)\n }\n }, [queryClient, state])\n}\n\nexport interface HydrateProps {\n state?: unknown\n options?: HydrateOptions\n children?: React.ReactNode\n}\n\nexport const Hydrate = ({ children, options, state }: HydrateProps) => {\n useHydrate(state, options)\n return children as React.ReactElement\n}\n"],"names":["optionsRef","state","useHydrate"],"mappings":";;;;;AAQO;;;AAI8B;AAEnC;AACAA;AAGA;AACA;AACA;;;AAEE;;AAEC;AACF;AACF;AAQM;;;AAAsCC;AAArB;AACtBC;AACA;AACD;;"}
@@ -1,66 +0,0 @@
1
- 'use client';
2
- import * as React from 'react';
3
-
4
- const defaultContext = /*#__PURE__*/React.createContext(undefined);
5
- const QueryClientSharingContext = /*#__PURE__*/React.createContext(false); // If we are given a context, we will use it.
6
- // Otherwise, if contextSharing is on, we share the first and at least one
7
- // instance of the context across the window
8
- // to ensure that if React Query is used across
9
- // different bundles or microfrontends they will
10
- // all use the same **instance** of context, regardless
11
- // of module scoping.
12
-
13
- function getQueryClientContext(context, contextSharing) {
14
- if (context) {
15
- return context;
16
- }
17
-
18
- if (contextSharing && typeof window !== 'undefined') {
19
- if (!window.ReactQueryClientContext) {
20
- window.ReactQueryClientContext = defaultContext;
21
- }
22
-
23
- return window.ReactQueryClientContext;
24
- }
25
-
26
- return defaultContext;
27
- }
28
-
29
- const useQueryClient = ({
30
- context
31
- } = {}) => {
32
- const queryClient = React.useContext(getQueryClientContext(context, React.useContext(QueryClientSharingContext)));
33
-
34
- if (!queryClient) {
35
- throw new Error('No QueryClient set, use QueryClientProvider to set one');
36
- }
37
-
38
- return queryClient;
39
- };
40
- const QueryClientProvider = ({
41
- client,
42
- children,
43
- context,
44
- contextSharing = false
45
- }) => {
46
- React.useEffect(() => {
47
- client.mount();
48
- return () => {
49
- client.unmount();
50
- };
51
- }, [client]);
52
-
53
- if (process.env.NODE_ENV !== 'production' && contextSharing) {
54
- client.getLogger().error("The contextSharing option has been deprecated and will be removed in the next major version");
55
- }
56
-
57
- const Context = getQueryClientContext(context, contextSharing);
58
- return /*#__PURE__*/React.createElement(QueryClientSharingContext.Provider, {
59
- value: !context && contextSharing
60
- }, /*#__PURE__*/React.createElement(Context.Provider, {
61
- value: client
62
- }, children));
63
- };
64
-
65
- export { QueryClientProvider, defaultContext, useQueryClient };
66
- //# sourceMappingURL=QueryClientProvider.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"QueryClientProvider.esm.js","sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { QueryClient } from '@tanstack/query-core'\nimport type { ContextOptions } from './types'\n\ndeclare global {\n interface Window {\n ReactQueryClientContext?: React.Context<QueryClient | undefined>\n }\n}\n\nexport const defaultContext = React.createContext<QueryClient | undefined>(\n undefined,\n)\nconst QueryClientSharingContext = React.createContext<boolean>(false)\n\n// If we are given a context, we will use it.\n// Otherwise, if contextSharing is on, we share the first and at least one\n// instance of the context across the window\n// to ensure that if React Query is used across\n// different bundles or microfrontends they will\n// all use the same **instance** of context, regardless\n// of module scoping.\nfunction getQueryClientContext(\n context: React.Context<QueryClient | undefined> | undefined,\n contextSharing: boolean,\n) {\n if (context) {\n return context\n }\n if (contextSharing && typeof window !== 'undefined') {\n if (!window.ReactQueryClientContext) {\n window.ReactQueryClientContext = defaultContext\n }\n\n return window.ReactQueryClientContext\n }\n\n return defaultContext\n}\n\nexport const useQueryClient = ({ context }: ContextOptions = {}) => {\n const queryClient = React.useContext(\n getQueryClientContext(context, React.useContext(QueryClientSharingContext)),\n )\n\n if (!queryClient) {\n throw new Error('No QueryClient set, use QueryClientProvider to set one')\n }\n\n return queryClient\n}\n\ntype QueryClientProviderPropsBase = {\n client: QueryClient\n children?: React.ReactNode\n}\ntype QueryClientProviderPropsWithContext = ContextOptions & {\n contextSharing?: never\n} & QueryClientProviderPropsBase\ntype QueryClientProviderPropsWithContextSharing = {\n context?: never\n contextSharing?: boolean\n} & QueryClientProviderPropsBase\n\nexport type QueryClientProviderProps =\n | QueryClientProviderPropsWithContext\n | QueryClientProviderPropsWithContextSharing\n\nexport const QueryClientProvider = ({\n client,\n children,\n context,\n contextSharing = false,\n}: QueryClientProviderProps): JSX.Element => {\n React.useEffect(() => {\n client.mount()\n return () => {\n client.unmount()\n }\n }, [client])\n\n if (process.env.NODE_ENV !== 'production' && contextSharing) {\n client\n .getLogger()\n .error(\n `The contextSharing option has been deprecated and will be removed in the next major version`,\n )\n }\n\n const Context = getQueryClientContext(context, contextSharing)\n\n return (\n <QueryClientSharingContext.Provider value={!context && contextSharing}>\n <Context.Provider value={client}>{children}</Context.Provider>\n </QueryClientSharingContext.Provider>\n )\n}\n"],"names":["context","contextSharing","client"],"mappings":";;;AAYO;AAGP;AAGA;AACA;AACA;AACA;AACA;AACA;;AACA;AAIE;AACE;AACD;;AACD;AACE;;AAEC;;;AAGF;;AAED;AACD;;AAEM;AAA0BA;AAAF;AAC7B;;;AAKE;AACD;;AAED;AACD;AAkBM;;;;AAILC;AAJkC;;AAOhCC;AACA;AACEA;;;;;;AAUH;;AAED;;;;AAIsB;;AAGvB;;"}
@@ -1,92 +0,0 @@
1
- 'use client';
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var React = require('react');
7
-
8
- function _interopNamespace(e) {
9
- if (e && e.__esModule) return e;
10
- var n = Object.create(null);
11
- if (e) {
12
- Object.keys(e).forEach(function (k) {
13
- if (k !== 'default') {
14
- var d = Object.getOwnPropertyDescriptor(e, k);
15
- Object.defineProperty(n, k, d.get ? d : {
16
- enumerable: true,
17
- get: function () { return e[k]; }
18
- });
19
- }
20
- });
21
- }
22
- n["default"] = e;
23
- return Object.freeze(n);
24
- }
25
-
26
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
27
-
28
- const defaultContext = /*#__PURE__*/React__namespace.createContext(undefined);
29
- const QueryClientSharingContext = /*#__PURE__*/React__namespace.createContext(false); // If we are given a context, we will use it.
30
- // Otherwise, if contextSharing is on, we share the first and at least one
31
- // instance of the context across the window
32
- // to ensure that if React Query is used across
33
- // different bundles or microfrontends they will
34
- // all use the same **instance** of context, regardless
35
- // of module scoping.
36
-
37
- function getQueryClientContext(context, contextSharing) {
38
- if (context) {
39
- return context;
40
- }
41
-
42
- if (contextSharing && typeof window !== 'undefined') {
43
- if (!window.ReactQueryClientContext) {
44
- window.ReactQueryClientContext = defaultContext;
45
- }
46
-
47
- return window.ReactQueryClientContext;
48
- }
49
-
50
- return defaultContext;
51
- }
52
-
53
- const useQueryClient = ({
54
- context
55
- } = {}) => {
56
- const queryClient = React__namespace.useContext(getQueryClientContext(context, React__namespace.useContext(QueryClientSharingContext)));
57
-
58
- if (!queryClient) {
59
- throw new Error('No QueryClient set, use QueryClientProvider to set one');
60
- }
61
-
62
- return queryClient;
63
- };
64
- const QueryClientProvider = ({
65
- client,
66
- children,
67
- context,
68
- contextSharing = false
69
- }) => {
70
- React__namespace.useEffect(() => {
71
- client.mount();
72
- return () => {
73
- client.unmount();
74
- };
75
- }, [client]);
76
-
77
- if (process.env.NODE_ENV !== 'production' && contextSharing) {
78
- client.getLogger().error("The contextSharing option has been deprecated and will be removed in the next major version");
79
- }
80
-
81
- const Context = getQueryClientContext(context, contextSharing);
82
- return /*#__PURE__*/React__namespace.createElement(QueryClientSharingContext.Provider, {
83
- value: !context && contextSharing
84
- }, /*#__PURE__*/React__namespace.createElement(Context.Provider, {
85
- value: client
86
- }, children));
87
- };
88
-
89
- exports.QueryClientProvider = QueryClientProvider;
90
- exports.defaultContext = defaultContext;
91
- exports.useQueryClient = useQueryClient;
92
- //# sourceMappingURL=QueryClientProvider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"QueryClientProvider.js","sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { QueryClient } from '@tanstack/query-core'\nimport type { ContextOptions } from './types'\n\ndeclare global {\n interface Window {\n ReactQueryClientContext?: React.Context<QueryClient | undefined>\n }\n}\n\nexport const defaultContext = React.createContext<QueryClient | undefined>(\n undefined,\n)\nconst QueryClientSharingContext = React.createContext<boolean>(false)\n\n// If we are given a context, we will use it.\n// Otherwise, if contextSharing is on, we share the first and at least one\n// instance of the context across the window\n// to ensure that if React Query is used across\n// different bundles or microfrontends they will\n// all use the same **instance** of context, regardless\n// of module scoping.\nfunction getQueryClientContext(\n context: React.Context<QueryClient | undefined> | undefined,\n contextSharing: boolean,\n) {\n if (context) {\n return context\n }\n if (contextSharing && typeof window !== 'undefined') {\n if (!window.ReactQueryClientContext) {\n window.ReactQueryClientContext = defaultContext\n }\n\n return window.ReactQueryClientContext\n }\n\n return defaultContext\n}\n\nexport const useQueryClient = ({ context }: ContextOptions = {}) => {\n const queryClient = React.useContext(\n getQueryClientContext(context, React.useContext(QueryClientSharingContext)),\n )\n\n if (!queryClient) {\n throw new Error('No QueryClient set, use QueryClientProvider to set one')\n }\n\n return queryClient\n}\n\ntype QueryClientProviderPropsBase = {\n client: QueryClient\n children?: React.ReactNode\n}\ntype QueryClientProviderPropsWithContext = ContextOptions & {\n contextSharing?: never\n} & QueryClientProviderPropsBase\ntype QueryClientProviderPropsWithContextSharing = {\n context?: never\n contextSharing?: boolean\n} & QueryClientProviderPropsBase\n\nexport type QueryClientProviderProps =\n | QueryClientProviderPropsWithContext\n | QueryClientProviderPropsWithContextSharing\n\nexport const QueryClientProvider = ({\n client,\n children,\n context,\n contextSharing = false,\n}: QueryClientProviderProps): JSX.Element => {\n React.useEffect(() => {\n client.mount()\n return () => {\n client.unmount()\n }\n }, [client])\n\n if (process.env.NODE_ENV !== 'production' && contextSharing) {\n client\n .getLogger()\n .error(\n `The contextSharing option has been deprecated and will be removed in the next major version`,\n )\n }\n\n const Context = getQueryClientContext(context, contextSharing)\n\n return (\n <QueryClientSharingContext.Provider value={!context && contextSharing}>\n <Context.Provider value={client}>{children}</Context.Provider>\n </QueryClientSharingContext.Provider>\n )\n}\n"],"names":["context","contextSharing","client"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAYO;AAGP;AAGA;AACA;AACA;AACA;AACA;AACA;;AACA;AAIE;AACE;AACD;;AACD;AACE;;AAEC;;;AAGF;;AAED;AACD;;AAEM;AAA0BA;AAAF;AAC7B;;;AAKE;AACD;;AAED;AACD;AAkBM;;;;AAILC;AAJkC;;AAOhCC;AACA;AACEA;;;;;;AAUH;;AAED;;;;AAIsB;;AAGvB;;;;"}
@@ -1,66 +0,0 @@
1
- 'use client';
2
- import * as React from 'react';
3
-
4
- const defaultContext = /*#__PURE__*/React.createContext(undefined);
5
- const QueryClientSharingContext = /*#__PURE__*/React.createContext(false); // If we are given a context, we will use it.
6
- // Otherwise, if contextSharing is on, we share the first and at least one
7
- // instance of the context across the window
8
- // to ensure that if React Query is used across
9
- // different bundles or microfrontends they will
10
- // all use the same **instance** of context, regardless
11
- // of module scoping.
12
-
13
- function getQueryClientContext(context, contextSharing) {
14
- if (context) {
15
- return context;
16
- }
17
-
18
- if (contextSharing && typeof window !== 'undefined') {
19
- if (!window.ReactQueryClientContext) {
20
- window.ReactQueryClientContext = defaultContext;
21
- }
22
-
23
- return window.ReactQueryClientContext;
24
- }
25
-
26
- return defaultContext;
27
- }
28
-
29
- const useQueryClient = ({
30
- context
31
- } = {}) => {
32
- const queryClient = React.useContext(getQueryClientContext(context, React.useContext(QueryClientSharingContext)));
33
-
34
- if (!queryClient) {
35
- throw new Error('No QueryClient set, use QueryClientProvider to set one');
36
- }
37
-
38
- return queryClient;
39
- };
40
- const QueryClientProvider = ({
41
- client,
42
- children,
43
- context,
44
- contextSharing = false
45
- }) => {
46
- React.useEffect(() => {
47
- client.mount();
48
- return () => {
49
- client.unmount();
50
- };
51
- }, [client]);
52
-
53
- if (process.env.NODE_ENV !== 'production' && contextSharing) {
54
- client.getLogger().error("The contextSharing option has been deprecated and will be removed in the next major version");
55
- }
56
-
57
- const Context = getQueryClientContext(context, contextSharing);
58
- return /*#__PURE__*/React.createElement(QueryClientSharingContext.Provider, {
59
- value: !context && contextSharing
60
- }, /*#__PURE__*/React.createElement(Context.Provider, {
61
- value: client
62
- }, children));
63
- };
64
-
65
- export { QueryClientProvider, defaultContext, useQueryClient };
66
- //# sourceMappingURL=QueryClientProvider.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"QueryClientProvider.mjs","sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { QueryClient } from '@tanstack/query-core'\nimport type { ContextOptions } from './types'\n\ndeclare global {\n interface Window {\n ReactQueryClientContext?: React.Context<QueryClient | undefined>\n }\n}\n\nexport const defaultContext = React.createContext<QueryClient | undefined>(\n undefined,\n)\nconst QueryClientSharingContext = React.createContext<boolean>(false)\n\n// If we are given a context, we will use it.\n// Otherwise, if contextSharing is on, we share the first and at least one\n// instance of the context across the window\n// to ensure that if React Query is used across\n// different bundles or microfrontends they will\n// all use the same **instance** of context, regardless\n// of module scoping.\nfunction getQueryClientContext(\n context: React.Context<QueryClient | undefined> | undefined,\n contextSharing: boolean,\n) {\n if (context) {\n return context\n }\n if (contextSharing && typeof window !== 'undefined') {\n if (!window.ReactQueryClientContext) {\n window.ReactQueryClientContext = defaultContext\n }\n\n return window.ReactQueryClientContext\n }\n\n return defaultContext\n}\n\nexport const useQueryClient = ({ context }: ContextOptions = {}) => {\n const queryClient = React.useContext(\n getQueryClientContext(context, React.useContext(QueryClientSharingContext)),\n )\n\n if (!queryClient) {\n throw new Error('No QueryClient set, use QueryClientProvider to set one')\n }\n\n return queryClient\n}\n\ntype QueryClientProviderPropsBase = {\n client: QueryClient\n children?: React.ReactNode\n}\ntype QueryClientProviderPropsWithContext = ContextOptions & {\n contextSharing?: never\n} & QueryClientProviderPropsBase\ntype QueryClientProviderPropsWithContextSharing = {\n context?: never\n contextSharing?: boolean\n} & QueryClientProviderPropsBase\n\nexport type QueryClientProviderProps =\n | QueryClientProviderPropsWithContext\n | QueryClientProviderPropsWithContextSharing\n\nexport const QueryClientProvider = ({\n client,\n children,\n context,\n contextSharing = false,\n}: QueryClientProviderProps): JSX.Element => {\n React.useEffect(() => {\n client.mount()\n return () => {\n client.unmount()\n }\n }, [client])\n\n if (process.env.NODE_ENV !== 'production' && contextSharing) {\n client\n .getLogger()\n .error(\n `The contextSharing option has been deprecated and will be removed in the next major version`,\n )\n }\n\n const Context = getQueryClientContext(context, contextSharing)\n\n return (\n <QueryClientSharingContext.Provider value={!context && contextSharing}>\n <Context.Provider value={client}>{children}</Context.Provider>\n </QueryClientSharingContext.Provider>\n )\n}\n"],"names":["context","contextSharing","client"],"mappings":";;;AAYO;AAGP;AAGA;AACA;AACA;AACA;AACA;AACA;;AACA;AAIE;AACE;AACD;;AACD;AACE;;AAEC;;;AAGF;;AAED;AACD;;AAEM;AAA0BA;AAAF;AAC7B;;;AAKE;AACD;;AAED;AACD;AAkBM;;;;AAILC;AAJkC;;AAOhCC;AACA;AACEA;;;;;;AAUH;;AAED;;;;AAIsB;;AAGvB;;"}
@@ -1,33 +0,0 @@
1
- 'use client';
2
- import * as React from 'react';
3
-
4
- function createValue() {
5
- let isReset = false;
6
- return {
7
- clearReset: () => {
8
- isReset = false;
9
- },
10
- reset: () => {
11
- isReset = true;
12
- },
13
- isReset: () => {
14
- return isReset;
15
- }
16
- };
17
- }
18
-
19
- const QueryErrorResetBoundaryContext = /*#__PURE__*/React.createContext(createValue()); // HOOK
20
-
21
- const useQueryErrorResetBoundary = () => React.useContext(QueryErrorResetBoundaryContext); // COMPONENT
22
-
23
- const QueryErrorResetBoundary = ({
24
- children
25
- }) => {
26
- const [value] = React.useState(() => createValue());
27
- return /*#__PURE__*/React.createElement(QueryErrorResetBoundaryContext.Provider, {
28
- value: value
29
- }, typeof children === 'function' ? children(value) : children);
30
- };
31
-
32
- export { QueryErrorResetBoundary, useQueryErrorResetBoundary };
33
- //# sourceMappingURL=QueryErrorResetBoundary.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"QueryErrorResetBoundary.esm.js","sources":["../../src/QueryErrorResetBoundary.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\n// CONTEXT\n\nexport interface QueryErrorResetBoundaryValue {\n clearReset: () => void\n isReset: () => boolean\n reset: () => void\n}\n\nfunction createValue(): QueryErrorResetBoundaryValue {\n let isReset = false\n return {\n clearReset: () => {\n isReset = false\n },\n reset: () => {\n isReset = true\n },\n isReset: () => {\n return isReset\n },\n }\n}\n\nconst QueryErrorResetBoundaryContext = React.createContext(createValue())\n\n// HOOK\n\nexport const useQueryErrorResetBoundary = () =>\n React.useContext(QueryErrorResetBoundaryContext)\n\n// COMPONENT\n\nexport interface QueryErrorResetBoundaryProps {\n children:\n | ((value: QueryErrorResetBoundaryValue) => React.ReactNode)\n | React.ReactNode\n}\n\nexport const QueryErrorResetBoundary = ({\n children,\n}: QueryErrorResetBoundaryProps) => {\n const [value] = React.useState(() => createValue())\n return (\n <QueryErrorResetBoundaryContext.Provider value={value}>\n {typeof children === 'function'\n ? (children as Function)(value)\n : children}\n </QueryErrorResetBoundaryContext.Provider>\n )\n}\n"],"names":["clearReset","isReset","reset","children"],"mappings":";;;AAWA;;;AAGIA;AACEC;;AAEFC;AACED;;AAEFA;AACE;AACD;;AAEJ;;AAED;;AAIO;;AAWA;AACLE;AADsC;;;AAKK;;AAM5C;;"}