@tanstack/react-query 4.3.0-beta.3 → 4.3.1

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 (69) hide show
  1. package/build/lib/Hydrate.js +56 -0
  2. package/build/lib/Hydrate.js.map +1 -0
  3. package/build/lib/Hydrate.mjs +31 -0
  4. package/build/lib/Hydrate.mjs.map +1 -0
  5. package/build/lib/QueryClientProvider.js +86 -0
  6. package/build/lib/QueryClientProvider.js.map +1 -0
  7. package/build/lib/QueryClientProvider.mjs +60 -0
  8. package/build/lib/QueryClientProvider.mjs.map +1 -0
  9. package/build/lib/QueryErrorResetBoundary.js +57 -0
  10. package/build/lib/QueryErrorResetBoundary.js.map +1 -0
  11. package/build/lib/QueryErrorResetBoundary.mjs +32 -0
  12. package/build/lib/QueryErrorResetBoundary.mjs.map +1 -0
  13. package/build/lib/index.js +29 -613
  14. package/build/lib/index.js.map +1 -1
  15. package/build/lib/index.mjs +11 -577
  16. package/build/lib/index.mjs.map +1 -1
  17. package/build/lib/isRestoring.js +33 -0
  18. package/build/lib/isRestoring.js.map +1 -0
  19. package/build/lib/isRestoring.mjs +8 -0
  20. package/build/lib/isRestoring.mjs.map +1 -0
  21. package/build/lib/reactBatchedUpdates.js +30 -0
  22. package/build/lib/reactBatchedUpdates.js.map +1 -0
  23. package/build/lib/reactBatchedUpdates.mjs +6 -0
  24. package/build/lib/reactBatchedUpdates.mjs.map +1 -0
  25. package/build/lib/reactBatchedUpdates.native.js +13 -0
  26. package/build/lib/reactBatchedUpdates.native.js.map +1 -0
  27. package/build/lib/reactBatchedUpdates.native.mjs +2 -0
  28. package/build/lib/reactBatchedUpdates.native.mjs.map +1 -0
  29. package/build/lib/setBatchUpdatesFn.js +7 -0
  30. package/build/lib/setBatchUpdatesFn.js.map +1 -0
  31. package/build/lib/setBatchUpdatesFn.mjs +5 -0
  32. package/build/lib/setBatchUpdatesFn.mjs.map +1 -0
  33. package/build/lib/useBaseQuery.js +107 -0
  34. package/build/lib/useBaseQuery.js.map +1 -0
  35. package/build/lib/useBaseQuery.mjs +83 -0
  36. package/build/lib/useBaseQuery.mjs.map +1 -0
  37. package/build/lib/useInfiniteQuery.js +14 -0
  38. package/build/lib/useInfiniteQuery.js.map +1 -0
  39. package/build/lib/useInfiniteQuery.mjs +10 -0
  40. package/build/lib/useInfiniteQuery.mjs.map +1 -0
  41. package/build/lib/useIsFetching.js +40 -0
  42. package/build/lib/useIsFetching.js.map +1 -0
  43. package/build/lib/useIsFetching.mjs +16 -0
  44. package/build/lib/useIsFetching.mjs.map +1 -0
  45. package/build/lib/useIsMutating.js +40 -0
  46. package/build/lib/useIsMutating.js.map +1 -0
  47. package/build/lib/useIsMutating.mjs +16 -0
  48. package/build/lib/useIsMutating.mjs.map +1 -0
  49. package/build/lib/useMutation.js +58 -0
  50. package/build/lib/useMutation.js.map +1 -0
  51. package/build/lib/useMutation.mjs +34 -0
  52. package/build/lib/useMutation.mjs.map +1 -0
  53. package/build/lib/useQueries.js +61 -0
  54. package/build/lib/useQueries.js.map +1 -0
  55. package/build/lib/useQueries.mjs +37 -0
  56. package/build/lib/useQueries.mjs.map +1 -0
  57. package/build/lib/useQuery.js +14 -0
  58. package/build/lib/useQuery.js.map +1 -0
  59. package/build/lib/useQuery.mjs +10 -0
  60. package/build/lib/useQuery.mjs.map +1 -0
  61. package/build/lib/utils.js +15 -0
  62. package/build/lib/utils.js.map +1 -0
  63. package/build/lib/utils.mjs +11 -0
  64. package/build/lib/utils.mjs.map +1 -0
  65. package/build/umd/index.development.js +0 -20
  66. package/build/umd/index.development.js.map +1 -1
  67. package/build/umd/index.production.js +1 -22
  68. package/build/umd/index.production.js.map +1 -1
  69. package/package.json +3 -3
@@ -1,579 +1,13 @@
1
- /**
2
- * react-query
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- import { notifyManager, QueriesObserver, parseQueryArgs, QueryObserver, hydrate, parseFilterArgs, parseMutationFilterArgs, parseMutationArgs, MutationObserver, InfiniteQueryObserver } from '@tanstack/query-core';
1
+ import './setBatchUpdatesFn.mjs';
12
2
  export * from '@tanstack/query-core';
13
- import * as ReactDOM from 'react-dom';
14
- import * as React from 'react';
15
- import React__default from 'react';
16
-
17
- const unstable_batchedUpdates = ReactDOM.unstable_batchedUpdates;
18
-
19
- notifyManager.setBatchNotifyFunction(unstable_batchedUpdates);
20
-
21
- var shim = {exports: {}};
22
-
23
- var useSyncExternalStoreShim_production_min = {};
24
-
25
- /**
26
- * @license React
27
- * use-sync-external-store-shim.production.min.js
28
- *
29
- * Copyright (c) Facebook, Inc. and its affiliates.
30
- *
31
- * This source code is licensed under the MIT license found in the
32
- * LICENSE file in the root directory of this source tree.
33
- */
34
-
35
- var hasRequiredUseSyncExternalStoreShim_production_min;
36
-
37
- function requireUseSyncExternalStoreShim_production_min () {
38
- if (hasRequiredUseSyncExternalStoreShim_production_min) return useSyncExternalStoreShim_production_min;
39
- hasRequiredUseSyncExternalStoreShim_production_min = 1;
40
- var e=React__default;function h(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var k="function"===typeof Object.is?Object.is:h,l=e.useState,m=e.useEffect,n=e.useLayoutEffect,p=e.useDebugValue;function q(a,b){var d=b(),f=l({inst:{value:d,getSnapshot:b}}),c=f[0].inst,g=f[1];n(function(){c.value=d;c.getSnapshot=b;r(c)&&g({inst:c});},[a,d,b]);m(function(){r(c)&&g({inst:c});return a(function(){r(c)&&g({inst:c});})},[a]);p(d);return d}
41
- function r(a){var b=a.getSnapshot;a=a.value;try{var d=b();return !k(a,d)}catch(f){return !0}}function t(a,b){return b()}var u="undefined"===typeof window||"undefined"===typeof window.document||"undefined"===typeof window.document.createElement?t:q;useSyncExternalStoreShim_production_min.useSyncExternalStore=void 0!==e.useSyncExternalStore?e.useSyncExternalStore:u;
42
- return useSyncExternalStoreShim_production_min;
43
- }
44
-
45
- var useSyncExternalStoreShim_development = {};
46
-
47
- /**
48
- * @license React
49
- * use-sync-external-store-shim.development.js
50
- *
51
- * Copyright (c) Facebook, Inc. and its affiliates.
52
- *
53
- * This source code is licensed under the MIT license found in the
54
- * LICENSE file in the root directory of this source tree.
55
- */
56
-
57
- var hasRequiredUseSyncExternalStoreShim_development;
58
-
59
- function requireUseSyncExternalStoreShim_development () {
60
- if (hasRequiredUseSyncExternalStoreShim_development) return useSyncExternalStoreShim_development;
61
- hasRequiredUseSyncExternalStoreShim_development = 1;
62
-
63
- if (process.env.NODE_ENV !== "production") {
64
- (function() {
65
-
66
- /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
67
- if (
68
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
69
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
70
- 'function'
71
- ) {
72
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
73
- }
74
- var React = React__default;
75
-
76
- var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
77
-
78
- function error(format) {
79
- {
80
- {
81
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
82
- args[_key2 - 1] = arguments[_key2];
83
- }
84
-
85
- printWarning('error', format, args);
86
- }
87
- }
88
- }
89
-
90
- function printWarning(level, format, args) {
91
- // When changing this logic, you might want to also
92
- // update consoleWithStackDev.www.js as well.
93
- {
94
- var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
95
- var stack = ReactDebugCurrentFrame.getStackAddendum();
96
-
97
- if (stack !== '') {
98
- format += '%s';
99
- args = args.concat([stack]);
100
- } // eslint-disable-next-line react-internal/safe-string-coercion
101
-
102
-
103
- var argsWithFormat = args.map(function (item) {
104
- return String(item);
105
- }); // Careful: RN currently depends on this prefix
106
-
107
- argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
108
- // breaks IE9: https://github.com/facebook/react/issues/13610
109
- // eslint-disable-next-line react-internal/no-production-logging
110
-
111
- Function.prototype.apply.call(console[level], console, argsWithFormat);
112
- }
113
- }
114
-
115
- /**
116
- * inlined Object.is polyfill to avoid requiring consumers ship their own
117
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
118
- */
119
- function is(x, y) {
120
- return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
121
- ;
122
- }
123
-
124
- var objectIs = typeof Object.is === 'function' ? Object.is : is;
125
-
126
- // dispatch for CommonJS interop named imports.
127
-
128
- var useState = React.useState,
129
- useEffect = React.useEffect,
130
- useLayoutEffect = React.useLayoutEffect,
131
- useDebugValue = React.useDebugValue;
132
- var didWarnOld18Alpha = false;
133
- var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works
134
- // because of a very particular set of implementation details and assumptions
135
- // -- change any one of them and it will break. The most important assumption
136
- // is that updates are always synchronous, because concurrent rendering is
137
- // only available in versions of React that also have a built-in
138
- // useSyncExternalStore API. And we only use this shim when the built-in API
139
- // does not exist.
140
- //
141
- // Do not assume that the clever hacks used by this hook also work in general.
142
- // The point of this shim is to replace the need for hacks by other libraries.
143
-
144
- function useSyncExternalStore(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of
145
- // React do not expose a way to check if we're hydrating. So users of the shim
146
- // will need to track that themselves and return the correct value
147
- // from `getSnapshot`.
148
- getServerSnapshot) {
149
- {
150
- if (!didWarnOld18Alpha) {
151
- if (React.startTransition !== undefined) {
152
- didWarnOld18Alpha = true;
153
-
154
- error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.');
155
- }
156
- }
157
- } // Read the current snapshot from the store on every render. Again, this
158
- // breaks the rules of React, and only works here because of specific
159
- // implementation details, most importantly that updates are
160
- // always synchronous.
161
-
162
-
163
- var value = getSnapshot();
164
-
165
- {
166
- if (!didWarnUncachedGetSnapshot) {
167
- var cachedValue = getSnapshot();
168
-
169
- if (!objectIs(value, cachedValue)) {
170
- error('The result of getSnapshot should be cached to avoid an infinite loop');
171
-
172
- didWarnUncachedGetSnapshot = true;
173
- }
174
- }
175
- } // Because updates are synchronous, we don't queue them. Instead we force a
176
- // re-render whenever the subscribed state changes by updating an some
177
- // arbitrary useState hook. Then, during render, we call getSnapshot to read
178
- // the current value.
179
- //
180
- // Because we don't actually use the state returned by the useState hook, we
181
- // can save a bit of memory by storing other stuff in that slot.
182
- //
183
- // To implement the early bailout, we need to track some things on a mutable
184
- // object. Usually, we would put that in a useRef hook, but we can stash it in
185
- // our useState hook instead.
186
- //
187
- // To force a re-render, we call forceUpdate({inst}). That works because the
188
- // new object always fails an equality check.
189
-
190
-
191
- var _useState = useState({
192
- inst: {
193
- value: value,
194
- getSnapshot: getSnapshot
195
- }
196
- }),
197
- inst = _useState[0].inst,
198
- forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated
199
- // in the layout phase so we can access it during the tearing check that
200
- // happens on subscribe.
201
-
202
-
203
- useLayoutEffect(function () {
204
- inst.value = value;
205
- inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the
206
- // commit phase if there was an interleaved mutation. In concurrent mode
207
- // this can happen all the time, but even in synchronous mode, an earlier
208
- // effect may have mutated the store.
209
-
210
- if (checkIfSnapshotChanged(inst)) {
211
- // Force a re-render.
212
- forceUpdate({
213
- inst: inst
214
- });
215
- }
216
- }, [subscribe, value, getSnapshot]);
217
- useEffect(function () {
218
- // Check for changes right before subscribing. Subsequent changes will be
219
- // detected in the subscription handler.
220
- if (checkIfSnapshotChanged(inst)) {
221
- // Force a re-render.
222
- forceUpdate({
223
- inst: inst
224
- });
225
- }
226
-
227
- var handleStoreChange = function () {
228
- // TODO: Because there is no cross-renderer API for batching updates, it's
229
- // up to the consumer of this library to wrap their subscription event
230
- // with unstable_batchedUpdates. Should we try to detect when this isn't
231
- // the case and print a warning in development?
232
- // The store changed. Check if the snapshot changed since the last time we
233
- // read from the store.
234
- if (checkIfSnapshotChanged(inst)) {
235
- // Force a re-render.
236
- forceUpdate({
237
- inst: inst
238
- });
239
- }
240
- }; // Subscribe to the store and return a clean-up function.
241
-
242
-
243
- return subscribe(handleStoreChange);
244
- }, [subscribe]);
245
- useDebugValue(value);
246
- return value;
247
- }
248
-
249
- function checkIfSnapshotChanged(inst) {
250
- var latestGetSnapshot = inst.getSnapshot;
251
- var prevValue = inst.value;
252
-
253
- try {
254
- var nextValue = latestGetSnapshot();
255
- return !objectIs(prevValue, nextValue);
256
- } catch (error) {
257
- return true;
258
- }
259
- }
260
-
261
- function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
262
- // Note: The shim does not use getServerSnapshot, because pre-18 versions of
263
- // React do not expose a way to check if we're hydrating. So users of the shim
264
- // will need to track that themselves and return the correct value
265
- // from `getSnapshot`.
266
- return getSnapshot();
267
- }
268
-
269
- var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
270
-
271
- var isServerEnvironment = !canUseDOM;
272
-
273
- var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
274
- var useSyncExternalStore$2 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim;
275
-
276
- useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2;
277
- /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
278
- if (
279
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
280
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
281
- 'function'
282
- ) {
283
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
284
- }
285
-
286
- })();
287
- }
288
- return useSyncExternalStoreShim_development;
289
- }
290
-
291
- (function (module) {
292
-
293
- if (process.env.NODE_ENV === 'production') {
294
- module.exports = requireUseSyncExternalStoreShim_production_min();
295
- } else {
296
- module.exports = requireUseSyncExternalStoreShim_development();
297
- }
298
- } (shim));
299
-
300
- const defaultContext = /*#__PURE__*/React.createContext(undefined);
301
- const QueryClientSharingContext = /*#__PURE__*/React.createContext(false); // If we are given a context, we will use it.
302
- // Otherwise, if contextSharing is on, we share the first and at least one
303
- // instance of the context across the window
304
- // to ensure that if React Query is used across
305
- // different bundles or microfrontends they will
306
- // all use the same **instance** of context, regardless
307
- // of module scoping.
308
-
309
- function getQueryClientContext(context, contextSharing) {
310
- if (context) {
311
- return context;
312
- }
313
-
314
- if (contextSharing && typeof window !== 'undefined') {
315
- if (!window.ReactQueryClientContext) {
316
- window.ReactQueryClientContext = defaultContext;
317
- }
318
-
319
- return window.ReactQueryClientContext;
320
- }
321
-
322
- return defaultContext;
323
- }
324
-
325
- const useQueryClient = ({
326
- context
327
- } = {}) => {
328
- const queryClient = React.useContext(getQueryClientContext(context, React.useContext(QueryClientSharingContext)));
329
-
330
- if (!queryClient) {
331
- throw new Error('No QueryClient set, use QueryClientProvider to set one');
332
- }
333
-
334
- return queryClient;
335
- };
336
- const QueryClientProvider = ({
337
- client,
338
- children,
339
- context,
340
- contextSharing = false
341
- }) => {
342
- React.useEffect(() => {
343
- client.mount();
344
- return () => {
345
- client.unmount();
346
- };
347
- }, [client]);
348
- const Context = getQueryClientContext(context, contextSharing);
349
- return /*#__PURE__*/React.createElement(QueryClientSharingContext.Provider, {
350
- value: !context && contextSharing
351
- }, /*#__PURE__*/React.createElement(Context.Provider, {
352
- value: client
353
- }, children));
354
- };
355
-
356
- const IsRestoringContext = /*#__PURE__*/React.createContext(false);
357
- const useIsRestoring = () => React.useContext(IsRestoringContext);
358
- const IsRestoringProvider = IsRestoringContext.Provider;
359
-
360
- // - `context` is omitted as it is passed as a root-level option to `useQueries` instead.
361
-
362
- function useQueries({
363
- queries,
364
- context
365
- }) {
366
- const queryClient = useQueryClient({
367
- context
368
- });
369
- const isRestoring = useIsRestoring();
370
- const defaultedQueries = React.useMemo(() => queries.map(options => {
371
- const defaultedOptions = queryClient.defaultQueryOptions(options); // Make sure the results are already in fetching state before subscribing or updating options
372
-
373
- defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic';
374
- return defaultedOptions;
375
- }), [queries, queryClient, isRestoring]);
376
- const [observer] = React.useState(() => new QueriesObserver(queryClient, defaultedQueries));
377
- const result = observer.getOptimisticResult(defaultedQueries);
378
- shim.exports.useSyncExternalStore(React.useCallback(onStoreChange => isRestoring ? () => undefined : observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
379
- React.useEffect(() => {
380
- // Do not notify on updates because of changes in the options because
381
- // these changes should already be reflected in the optimistic result.
382
- observer.setQueries(defaultedQueries, {
383
- listeners: false
384
- });
385
- }, [defaultedQueries, observer]);
386
- return result;
387
- }
388
-
389
- function createValue() {
390
- let isReset = false;
391
- return {
392
- clearReset: () => {
393
- isReset = false;
394
- },
395
- reset: () => {
396
- isReset = true;
397
- },
398
- isReset: () => {
399
- return isReset;
400
- }
401
- };
402
- }
403
-
404
- const QueryErrorResetBoundaryContext = /*#__PURE__*/React.createContext(createValue()); // HOOK
405
-
406
- const useQueryErrorResetBoundary = () => React.useContext(QueryErrorResetBoundaryContext); // COMPONENT
407
-
408
- const QueryErrorResetBoundary = ({
409
- children
410
- }) => {
411
- const [value] = React.useState(() => createValue());
412
- return /*#__PURE__*/React.createElement(QueryErrorResetBoundaryContext.Provider, {
413
- value: value
414
- }, typeof children === 'function' ? children(value) : children);
415
- };
416
-
417
- function shouldThrowError(_useErrorBoundary, params) {
418
- // Allow useErrorBoundary function to override throwing behavior on a per-error basis
419
- if (typeof _useErrorBoundary === 'function') {
420
- return _useErrorBoundary(...params);
421
- }
422
-
423
- return !!_useErrorBoundary;
424
- }
425
-
426
- function useBaseQuery(options, Observer) {
427
- const queryClient = useQueryClient({
428
- context: options.context
429
- });
430
- const isRestoring = useIsRestoring();
431
- const errorResetBoundary = useQueryErrorResetBoundary();
432
- const defaultedOptions = queryClient.defaultQueryOptions(options); // Make sure results are optimistically set in fetching state before subscribing or updating options
433
-
434
- defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic'; // Include callbacks in batch renders
435
-
436
- if (defaultedOptions.onError) {
437
- defaultedOptions.onError = notifyManager.batchCalls(defaultedOptions.onError);
438
- }
439
-
440
- if (defaultedOptions.onSuccess) {
441
- defaultedOptions.onSuccess = notifyManager.batchCalls(defaultedOptions.onSuccess);
442
- }
443
-
444
- if (defaultedOptions.onSettled) {
445
- defaultedOptions.onSettled = notifyManager.batchCalls(defaultedOptions.onSettled);
446
- }
447
-
448
- if (defaultedOptions.suspense) {
449
- // Always set stale time when using suspense to prevent
450
- // fetching again when directly mounting after suspending
451
- if (typeof defaultedOptions.staleTime !== 'number') {
452
- defaultedOptions.staleTime = 1000;
453
- }
454
- }
455
-
456
- if (defaultedOptions.suspense || defaultedOptions.useErrorBoundary) {
457
- // Prevent retrying failed query if the error boundary has not been reset yet
458
- if (!errorResetBoundary.isReset()) {
459
- defaultedOptions.retryOnMount = false;
460
- }
461
- }
462
-
463
- const [observer] = React.useState(() => new Observer(queryClient, defaultedOptions));
464
- const result = observer.getOptimisticResult(defaultedOptions);
465
- shim.exports.useSyncExternalStore(React.useCallback(onStoreChange => isRestoring ? () => undefined : observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
466
- React.useEffect(() => {
467
- errorResetBoundary.clearReset();
468
- }, [errorResetBoundary]);
469
- React.useEffect(() => {
470
- // Do not notify on updates because of changes in the options because
471
- // these changes should already be reflected in the optimistic result.
472
- observer.setOptions(defaultedOptions, {
473
- listeners: false
474
- });
475
- }, [defaultedOptions, observer]); // Handle suspense
476
-
477
- if (defaultedOptions.suspense && result.isLoading && result.isFetching && !isRestoring) {
478
- throw observer.fetchOptimistic(defaultedOptions).then(({
479
- data
480
- }) => {
481
- defaultedOptions.onSuccess == null ? void 0 : defaultedOptions.onSuccess(data);
482
- defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(data, null);
483
- }).catch(error => {
484
- errorResetBoundary.clearReset();
485
- defaultedOptions.onError == null ? void 0 : defaultedOptions.onError(error);
486
- defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(undefined, error);
487
- });
488
- } // Handle error boundary
489
-
490
-
491
- if (result.isError && !errorResetBoundary.isReset() && !result.isFetching && shouldThrowError(defaultedOptions.useErrorBoundary, [result.error, observer.getCurrentQuery()])) {
492
- throw result.error;
493
- } // Handle result property usage tracking
494
-
495
-
496
- return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
497
- }
498
-
499
- function useQuery(arg1, arg2, arg3) {
500
- const parsedOptions = parseQueryArgs(arg1, arg2, arg3);
501
- return useBaseQuery(parsedOptions, QueryObserver);
502
- }
503
-
504
- function useHydrate(state, options = {}) {
505
- const queryClient = useQueryClient({
506
- context: options.context
507
- });
508
- const optionsRef = React.useRef(options);
509
- optionsRef.current = options; // Running hydrate again with the same queries is safe,
510
- // it wont overwrite or initialize existing queries,
511
- // relying on useMemo here is only a performance optimization.
512
- // hydrate can and should be run *during* render here for SSR to work properly
513
-
514
- React.useMemo(() => {
515
- if (state) {
516
- hydrate(queryClient, state, optionsRef.current);
517
- }
518
- }, [queryClient, state]);
519
- }
520
- const Hydrate = ({
521
- children,
522
- options,
523
- state
524
- }) => {
525
- useHydrate(state, options);
526
- return children;
527
- };
528
-
529
- function useIsFetching(arg1, arg2, arg3) {
530
- const [filters, options = {}] = parseFilterArgs(arg1, arg2, arg3);
531
- const queryClient = useQueryClient({
532
- context: options.context
533
- });
534
- const queryCache = queryClient.getQueryCache();
535
- return shim.exports.useSyncExternalStore(React.useCallback(onStoreChange => queryCache.subscribe(notifyManager.batchCalls(onStoreChange)), [queryCache]), () => queryClient.isFetching(filters), () => queryClient.isFetching(filters));
536
- }
537
-
538
- function useIsMutating(arg1, arg2, arg3) {
539
- const [filters, options = {}] = parseMutationFilterArgs(arg1, arg2, arg3);
540
- const queryClient = useQueryClient({
541
- context: options.context
542
- });
543
- const mutationCache = queryClient.getMutationCache();
544
- return shim.exports.useSyncExternalStore(React.useCallback(onStoreChange => mutationCache.subscribe(notifyManager.batchCalls(onStoreChange)), [mutationCache]), () => queryClient.isMutating(filters), () => queryClient.isMutating(filters));
545
- }
546
-
547
- function useMutation(arg1, arg2, arg3) {
548
- const options = parseMutationArgs(arg1, arg2, arg3);
549
- const queryClient = useQueryClient({
550
- context: options.context
551
- });
552
- const [observer] = React.useState(() => new MutationObserver(queryClient, options));
553
- React.useEffect(() => {
554
- observer.setOptions(options);
555
- }, [observer, options]);
556
- const result = shim.exports.useSyncExternalStore(React.useCallback(onStoreChange => observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
557
- const mutate = React.useCallback((variables, mutateOptions) => {
558
- observer.mutate(variables, mutateOptions).catch(noop);
559
- }, [observer]);
560
-
561
- if (result.error && shouldThrowError(observer.options.useErrorBoundary, [result.error])) {
562
- throw result.error;
563
- }
564
-
565
- return { ...result,
566
- mutate,
567
- mutateAsync: result.mutate
568
- };
569
- } // eslint-disable-next-line @typescript-eslint/no-empty-function
570
-
571
- function noop() {}
572
-
573
- function useInfiniteQuery(arg1, arg2, arg3) {
574
- const options = parseQueryArgs(arg1, arg2, arg3);
575
- return useBaseQuery(options, InfiniteQueryObserver);
576
- }
577
-
578
- export { Hydrate, IsRestoringProvider, QueryClientProvider, QueryErrorResetBoundary, defaultContext, useHydrate, useInfiniteQuery, useIsFetching, useIsMutating, useIsRestoring, useMutation, useQueries, useQuery, useQueryClient, useQueryErrorResetBoundary };
3
+ export { useQueries } from './useQueries.mjs';
4
+ export { useQuery } from './useQuery.mjs';
5
+ export { QueryClientProvider, defaultContext, useQueryClient } from './QueryClientProvider.mjs';
6
+ export { Hydrate, useHydrate } from './Hydrate.mjs';
7
+ export { QueryErrorResetBoundary, useQueryErrorResetBoundary } from './QueryErrorResetBoundary.mjs';
8
+ export { useIsFetching } from './useIsFetching.mjs';
9
+ export { useIsMutating } from './useIsMutating.mjs';
10
+ export { useMutation } from './useMutation.mjs';
11
+ export { useInfiniteQuery } from './useInfiniteQuery.mjs';
12
+ export { IsRestoringProvider, useIsRestoring } from './isRestoring.mjs';
579
13
  //# sourceMappingURL=index.mjs.map