@tanstack/react-query 4.3.6 → 4.3.8

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 (33) hide show
  1. package/build/lib/Hydrate.esm.js +31 -0
  2. package/build/lib/Hydrate.esm.js.map +1 -0
  3. package/build/lib/QueryClientProvider.esm.js +60 -0
  4. package/build/lib/QueryClientProvider.esm.js.map +1 -0
  5. package/build/lib/QueryErrorResetBoundary.esm.js +32 -0
  6. package/build/lib/QueryErrorResetBoundary.esm.js.map +1 -0
  7. package/build/lib/index.esm.js +13 -0
  8. package/build/lib/index.esm.js.map +1 -0
  9. package/build/lib/isRestoring.esm.js +8 -0
  10. package/build/lib/isRestoring.esm.js.map +1 -0
  11. package/build/lib/reactBatchedUpdates.esm.js +6 -0
  12. package/build/lib/reactBatchedUpdates.esm.js.map +1 -0
  13. package/build/lib/reactBatchedUpdates.native.esm.js +2 -0
  14. package/build/lib/reactBatchedUpdates.native.esm.js.map +1 -0
  15. package/build/lib/setBatchUpdatesFn.esm.js +5 -0
  16. package/build/lib/setBatchUpdatesFn.esm.js.map +1 -0
  17. package/build/lib/useBaseQuery.esm.js +83 -0
  18. package/build/lib/useBaseQuery.esm.js.map +1 -0
  19. package/build/lib/useInfiniteQuery.esm.js +10 -0
  20. package/build/lib/useInfiniteQuery.esm.js.map +1 -0
  21. package/build/lib/useIsFetching.esm.js +16 -0
  22. package/build/lib/useIsFetching.esm.js.map +1 -0
  23. package/build/lib/useIsMutating.esm.js +16 -0
  24. package/build/lib/useIsMutating.esm.js.map +1 -0
  25. package/build/lib/useMutation.esm.js +34 -0
  26. package/build/lib/useMutation.esm.js.map +1 -0
  27. package/build/lib/useQueries.esm.js +37 -0
  28. package/build/lib/useQueries.esm.js.map +1 -0
  29. package/build/lib/useQuery.esm.js +10 -0
  30. package/build/lib/useQuery.esm.js.map +1 -0
  31. package/build/lib/utils.esm.js +11 -0
  32. package/build/lib/utils.esm.js.map +1 -0
  33. package/package.json +3 -2
@@ -0,0 +1,31 @@
1
+ import * as React from 'react';
2
+ import { hydrate } from '@tanstack/query-core';
3
+ import { useQueryClient } from './QueryClientProvider.esm.js';
4
+
5
+ function useHydrate(state, options = {}) {
6
+ const queryClient = useQueryClient({
7
+ context: options.context
8
+ });
9
+ const optionsRef = React.useRef(options);
10
+ optionsRef.current = options; // Running hydrate again with the same queries is safe,
11
+ // it wont overwrite or initialize existing queries,
12
+ // relying on useMemo here is only a performance optimization.
13
+ // hydrate can and should be run *during* render here for SSR to work properly
14
+
15
+ React.useMemo(() => {
16
+ if (state) {
17
+ hydrate(queryClient, state, optionsRef.current);
18
+ }
19
+ }, [queryClient, state]);
20
+ }
21
+ const Hydrate = ({
22
+ children,
23
+ options,
24
+ state
25
+ }) => {
26
+ useHydrate(state, options);
27
+ return children;
28
+ };
29
+
30
+ export { Hydrate, useHydrate };
31
+ //# sourceMappingURL=Hydrate.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Hydrate.esm.js","sources":["../../src/Hydrate.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport { hydrate, HydrateOptions } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport { 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":["useHydrate","state","options","queryClient","useQueryClient","context","optionsRef","React","useRef","current","useMemo","hydrate","Hydrate","children"],"mappings":";;;;AAMO,SAASA,UAAT,CACLC,KADK,EAELC,OAAwC,GAAG,EAFtC,EAGL;EACA,MAAMC,WAAW,GAAGC,cAAc,CAAC;IAAEC,OAAO,EAAEH,OAAO,CAACG,OAAAA;AAAnB,GAAD,CAAlC,CAAA;AAEA,EAAA,MAAMC,UAAU,GAAGC,KAAK,CAACC,MAAN,CAAaN,OAAb,CAAnB,CAAA;AACAI,EAAAA,UAAU,CAACG,OAAX,GAAqBP,OAArB,CAJA;AAOA;AACA;AACA;;EACAK,KAAK,CAACG,OAAN,CAAc,MAAM;AAClB,IAAA,IAAIT,KAAJ,EAAW;MACTU,OAAO,CAACR,WAAD,EAAcF,KAAd,EAAqBK,UAAU,CAACG,OAAhC,CAAP,CAAA;AACD,KAAA;AACF,GAJD,EAIG,CAACN,WAAD,EAAcF,KAAd,CAJH,CAAA,CAAA;AAKD,CAAA;AAQM,MAAMW,OAAO,GAAG,CAAC;EAAEC,QAAF;EAAYX,OAAZ;AAAqBD,EAAAA,KAAAA;AAArB,CAAD,KAAgD;AACrED,EAAAA,UAAU,CAACC,KAAD,EAAQC,OAAR,CAAV,CAAA;AACA,EAAA,OAAOW,QAAP,CAAA;AACD;;;;"}
@@ -0,0 +1,60 @@
1
+ import * as React from 'react';
2
+
3
+ const defaultContext = /*#__PURE__*/React.createContext(undefined);
4
+ const QueryClientSharingContext = /*#__PURE__*/React.createContext(false); // If we are given a context, we will use it.
5
+ // Otherwise, if contextSharing is on, we share the first and at least one
6
+ // instance of the context across the window
7
+ // to ensure that if React Query is used across
8
+ // different bundles or microfrontends they will
9
+ // all use the same **instance** of context, regardless
10
+ // of module scoping.
11
+
12
+ function getQueryClientContext(context, contextSharing) {
13
+ if (context) {
14
+ return context;
15
+ }
16
+
17
+ if (contextSharing && typeof window !== 'undefined') {
18
+ if (!window.ReactQueryClientContext) {
19
+ window.ReactQueryClientContext = defaultContext;
20
+ }
21
+
22
+ return window.ReactQueryClientContext;
23
+ }
24
+
25
+ return defaultContext;
26
+ }
27
+
28
+ const useQueryClient = ({
29
+ context
30
+ } = {}) => {
31
+ const queryClient = React.useContext(getQueryClientContext(context, React.useContext(QueryClientSharingContext)));
32
+
33
+ if (!queryClient) {
34
+ throw new Error('No QueryClient set, use QueryClientProvider to set one');
35
+ }
36
+
37
+ return queryClient;
38
+ };
39
+ const QueryClientProvider = ({
40
+ client,
41
+ children,
42
+ context,
43
+ contextSharing = false
44
+ }) => {
45
+ React.useEffect(() => {
46
+ client.mount();
47
+ return () => {
48
+ client.unmount();
49
+ };
50
+ }, [client]);
51
+ const Context = getQueryClientContext(context, contextSharing);
52
+ return /*#__PURE__*/React.createElement(QueryClientSharingContext.Provider, {
53
+ value: !context && contextSharing
54
+ }, /*#__PURE__*/React.createElement(Context.Provider, {
55
+ value: client
56
+ }, children));
57
+ };
58
+
59
+ export { QueryClientProvider, defaultContext, useQueryClient };
60
+ //# sourceMappingURL=QueryClientProvider.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryClientProvider.esm.js","sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport { QueryClient } from '@tanstack/query-core'\nimport { 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 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":["defaultContext","React","createContext","undefined","QueryClientSharingContext","getQueryClientContext","context","contextSharing","window","ReactQueryClientContext","useQueryClient","queryClient","useContext","Error","QueryClientProvider","client","children","useEffect","mount","unmount","Context"],"mappings":";;AAWO,MAAMA,cAAc,gBAAGC,KAAK,CAACC,aAAN,CAC5BC,SAD4B,EAAvB;AAGP,MAAMC,yBAAyB,gBAAGH,KAAK,CAACC,aAAN,CAA6B,KAA7B,CAAlC;AAGA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASG,qBAAT,CACEC,OADF,EAEEC,cAFF,EAGE;AACA,EAAA,IAAID,OAAJ,EAAa;AACX,IAAA,OAAOA,OAAP,CAAA;AACD,GAAA;;AACD,EAAA,IAAIC,cAAc,IAAI,OAAOC,MAAP,KAAkB,WAAxC,EAAqD;AACnD,IAAA,IAAI,CAACA,MAAM,CAACC,uBAAZ,EAAqC;MACnCD,MAAM,CAACC,uBAAP,GAAiCT,cAAjC,CAAA;AACD,KAAA;;IAED,OAAOQ,MAAM,CAACC,uBAAd,CAAA;AACD,GAAA;;AAED,EAAA,OAAOT,cAAP,CAAA;AACD,CAAA;;AAEM,MAAMU,cAAc,GAAG,CAAC;AAAEJ,EAAAA,OAAAA;AAAF,CAAA,GAA8B,EAA/B,KAAsC;AAClE,EAAA,MAAMK,WAAW,GAAGV,KAAK,CAACW,UAAN,CAClBP,qBAAqB,CAACC,OAAD,EAAUL,KAAK,CAACW,UAAN,CAAiBR,yBAAjB,CAAV,CADH,CAApB,CAAA;;EAIA,IAAI,CAACO,WAAL,EAAkB;AAChB,IAAA,MAAM,IAAIE,KAAJ,CAAU,wDAAV,CAAN,CAAA;AACD,GAAA;;AAED,EAAA,OAAOF,WAAP,CAAA;AACD,EAVM;AA4BA,MAAMG,mBAAmB,GAAG,CAAC;EAClCC,MADkC;EAElCC,QAFkC;EAGlCV,OAHkC;AAIlCC,EAAAA,cAAc,GAAG,KAAA;AAJiB,CAAD,KAKU;EAC3CN,KAAK,CAACgB,SAAN,CAAgB,MAAM;AACpBF,IAAAA,MAAM,CAACG,KAAP,EAAA,CAAA;AACA,IAAA,OAAO,MAAM;AACXH,MAAAA,MAAM,CAACI,OAAP,EAAA,CAAA;KADF,CAAA;GAFF,EAKG,CAACJ,MAAD,CALH,CAAA,CAAA;AAOA,EAAA,MAAMK,OAAO,GAAGf,qBAAqB,CAACC,OAAD,EAAUC,cAAV,CAArC,CAAA;EAEA,oBACE,KAAA,CAAA,aAAA,CAAC,yBAAD,CAA2B,QAA3B,EAAA;IAAoC,KAAK,EAAE,CAACD,OAAD,IAAYC,cAAAA;GACrD,eAAA,KAAA,CAAA,aAAA,CAAC,OAAD,CAAS,QAAT,EAAA;AAAkB,IAAA,KAAK,EAAEQ,MAAAA;GAASC,EAAAA,QAAlC,CADF,CADF,CAAA;AAKD;;;;"}
@@ -0,0 +1,32 @@
1
+ import * as React from 'react';
2
+
3
+ function createValue() {
4
+ let isReset = false;
5
+ return {
6
+ clearReset: () => {
7
+ isReset = false;
8
+ },
9
+ reset: () => {
10
+ isReset = true;
11
+ },
12
+ isReset: () => {
13
+ return isReset;
14
+ }
15
+ };
16
+ }
17
+
18
+ const QueryErrorResetBoundaryContext = /*#__PURE__*/React.createContext(createValue()); // HOOK
19
+
20
+ const useQueryErrorResetBoundary = () => React.useContext(QueryErrorResetBoundaryContext); // COMPONENT
21
+
22
+ const QueryErrorResetBoundary = ({
23
+ children
24
+ }) => {
25
+ const [value] = React.useState(() => createValue());
26
+ return /*#__PURE__*/React.createElement(QueryErrorResetBoundaryContext.Provider, {
27
+ value: value
28
+ }, typeof children === 'function' ? children(value) : children);
29
+ };
30
+
31
+ export { QueryErrorResetBoundary, useQueryErrorResetBoundary };
32
+ //# sourceMappingURL=QueryErrorResetBoundary.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryErrorResetBoundary.esm.js","sources":["../../src/QueryErrorResetBoundary.tsx"],"sourcesContent":["import * as React from 'react'\n\n// CONTEXT\n\ninterface 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":["createValue","isReset","clearReset","reset","QueryErrorResetBoundaryContext","React","createContext","useQueryErrorResetBoundary","useContext","QueryErrorResetBoundary","children","value","useState"],"mappings":";;AAUA,SAASA,WAAT,GAAqD;EACnD,IAAIC,OAAO,GAAG,KAAd,CAAA;EACA,OAAO;AACLC,IAAAA,UAAU,EAAE,MAAM;AAChBD,MAAAA,OAAO,GAAG,KAAV,CAAA;KAFG;AAILE,IAAAA,KAAK,EAAE,MAAM;AACXF,MAAAA,OAAO,GAAG,IAAV,CAAA;KALG;AAOLA,IAAAA,OAAO,EAAE,MAAM;AACb,MAAA,OAAOA,OAAP,CAAA;AACD,KAAA;GATH,CAAA;AAWD,CAAA;;AAED,MAAMG,8BAA8B,gBAAGC,KAAK,CAACC,aAAN,CAAoBN,WAAW,EAA/B,CAAvC;;AAIO,MAAMO,0BAA0B,GAAG,MACxCF,KAAK,CAACG,UAAN,CAAiBJ,8BAAjB;;AAUK,MAAMK,uBAAuB,GAAG,CAAC;AACtCC,EAAAA,QAAAA;AADsC,CAAD,KAEH;EAClC,MAAM,CAACC,KAAD,CAAA,GAAUN,KAAK,CAACO,QAAN,CAAe,MAAMZ,WAAW,EAAhC,CAAhB,CAAA;EACA,oBACE,KAAA,CAAA,aAAA,CAAC,8BAAD,CAAgC,QAAhC,EAAA;AAAyC,IAAA,KAAK,EAAEW,KAAAA;GAC7C,EAAA,OAAOD,QAAP,KAAoB,UAApB,GACIA,QAAD,CAAuBC,KAAvB,CADH,GAEGD,QAHN,CADF,CAAA;AAOD;;;;"}
@@ -0,0 +1,13 @@
1
+ import './setBatchUpdatesFn.esm.js';
2
+ export * from '@tanstack/query-core';
3
+ export { useQueries } from './useQueries.esm.js';
4
+ export { useQuery } from './useQuery.esm.js';
5
+ export { QueryClientProvider, defaultContext, useQueryClient } from './QueryClientProvider.esm.js';
6
+ export { Hydrate, useHydrate } from './Hydrate.esm.js';
7
+ export { QueryErrorResetBoundary, useQueryErrorResetBoundary } from './QueryErrorResetBoundary.esm.js';
8
+ export { useIsFetching } from './useIsFetching.esm.js';
9
+ export { useIsMutating } from './useIsMutating.esm.js';
10
+ export { useMutation } from './useMutation.esm.js';
11
+ export { useInfiniteQuery } from './useInfiniteQuery.esm.js';
12
+ export { IsRestoringProvider, useIsRestoring } from './isRestoring.esm.js';
13
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+
3
+ const IsRestoringContext = /*#__PURE__*/React.createContext(false);
4
+ const useIsRestoring = () => React.useContext(IsRestoringContext);
5
+ const IsRestoringProvider = IsRestoringContext.Provider;
6
+
7
+ export { IsRestoringProvider, useIsRestoring };
8
+ //# sourceMappingURL=isRestoring.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isRestoring.esm.js","sources":["../../src/isRestoring.tsx"],"sourcesContent":["import * as React from 'react'\n\nconst IsRestoringContext = React.createContext(false)\n\nexport const useIsRestoring = () => React.useContext(IsRestoringContext)\nexport const IsRestoringProvider = IsRestoringContext.Provider\n"],"names":["IsRestoringContext","React","createContext","useIsRestoring","useContext","IsRestoringProvider","Provider"],"mappings":";;AAEA,MAAMA,kBAAkB,gBAAGC,KAAK,CAACC,aAAN,CAAoB,KAApB,CAA3B,CAAA;AAEO,MAAMC,cAAc,GAAG,MAAMF,KAAK,CAACG,UAAN,CAAiBJ,kBAAjB,EAA7B;AACMK,MAAAA,mBAAmB,GAAGL,kBAAkB,CAACM;;;;"}
@@ -0,0 +1,6 @@
1
+ import * as ReactDOM from 'react-dom';
2
+
3
+ const unstable_batchedUpdates = ReactDOM.unstable_batchedUpdates;
4
+
5
+ export { unstable_batchedUpdates };
6
+ //# sourceMappingURL=reactBatchedUpdates.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactBatchedUpdates.esm.js","sources":["../../src/reactBatchedUpdates.ts"],"sourcesContent":["import * as ReactDOM from 'react-dom'\nexport const unstable_batchedUpdates = ReactDOM.unstable_batchedUpdates\n"],"names":["unstable_batchedUpdates","ReactDOM"],"mappings":";;AACaA,MAAAA,uBAAuB,GAAGC,QAAQ,CAACD;;;;"}
@@ -0,0 +1,2 @@
1
+ export { unstable_batchedUpdates } from 'react-native';
2
+ //# sourceMappingURL=reactBatchedUpdates.native.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactBatchedUpdates.native.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { notifyManager } from '@tanstack/query-core';
2
+ import { unstable_batchedUpdates } from './reactBatchedUpdates.esm.js';
3
+
4
+ notifyManager.setBatchNotifyFunction(unstable_batchedUpdates);
5
+ //# sourceMappingURL=setBatchUpdatesFn.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setBatchUpdatesFn.esm.js","sources":["../../src/setBatchUpdatesFn.ts"],"sourcesContent":["import { notifyManager } from '@tanstack/query-core'\nimport { unstable_batchedUpdates } from './reactBatchedUpdates'\n\nnotifyManager.setBatchNotifyFunction(unstable_batchedUpdates)\n"],"names":["notifyManager","setBatchNotifyFunction","unstable_batchedUpdates"],"mappings":";;;AAGAA,aAAa,CAACC,sBAAd,CAAqCC,uBAArC,CAAA"}
@@ -0,0 +1,83 @@
1
+ import * as React from 'react';
2
+ import { notifyManager } from '@tanstack/query-core';
3
+ import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary.esm.js';
4
+ import { useQueryClient } from './QueryClientProvider.esm.js';
5
+ import { shouldThrowError } from './utils.esm.js';
6
+ import { useIsRestoring } from './isRestoring.esm.js';
7
+ import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
8
+
9
+ function useBaseQuery(options, Observer) {
10
+ const queryClient = useQueryClient({
11
+ context: options.context
12
+ });
13
+ const isRestoring = useIsRestoring();
14
+ const errorResetBoundary = useQueryErrorResetBoundary();
15
+ const defaultedOptions = queryClient.defaultQueryOptions(options); // Make sure results are optimistically set in fetching state before subscribing or updating options
16
+
17
+ defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic'; // Include callbacks in batch renders
18
+
19
+ if (defaultedOptions.onError) {
20
+ defaultedOptions.onError = notifyManager.batchCalls(defaultedOptions.onError);
21
+ }
22
+
23
+ if (defaultedOptions.onSuccess) {
24
+ defaultedOptions.onSuccess = notifyManager.batchCalls(defaultedOptions.onSuccess);
25
+ }
26
+
27
+ if (defaultedOptions.onSettled) {
28
+ defaultedOptions.onSettled = notifyManager.batchCalls(defaultedOptions.onSettled);
29
+ }
30
+
31
+ if (defaultedOptions.suspense) {
32
+ // Always set stale time when using suspense to prevent
33
+ // fetching again when directly mounting after suspending
34
+ if (typeof defaultedOptions.staleTime !== 'number') {
35
+ defaultedOptions.staleTime = 1000;
36
+ }
37
+ }
38
+
39
+ if (defaultedOptions.suspense || defaultedOptions.useErrorBoundary) {
40
+ // Prevent retrying failed query if the error boundary has not been reset yet
41
+ if (!errorResetBoundary.isReset()) {
42
+ defaultedOptions.retryOnMount = false;
43
+ }
44
+ }
45
+
46
+ const [observer] = React.useState(() => new Observer(queryClient, defaultedOptions));
47
+ const result = observer.getOptimisticResult(defaultedOptions);
48
+ useSyncExternalStore(React.useCallback(onStoreChange => isRestoring ? () => undefined : observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
49
+ React.useEffect(() => {
50
+ errorResetBoundary.clearReset();
51
+ }, [errorResetBoundary]);
52
+ React.useEffect(() => {
53
+ // Do not notify on updates because of changes in the options because
54
+ // these changes should already be reflected in the optimistic result.
55
+ observer.setOptions(defaultedOptions, {
56
+ listeners: false
57
+ });
58
+ }, [defaultedOptions, observer]); // Handle suspense
59
+
60
+ if (defaultedOptions.suspense && result.isLoading && result.isFetching && !isRestoring) {
61
+ throw observer.fetchOptimistic(defaultedOptions).then(({
62
+ data
63
+ }) => {
64
+ defaultedOptions.onSuccess == null ? void 0 : defaultedOptions.onSuccess(data);
65
+ defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(data, null);
66
+ }).catch(error => {
67
+ errorResetBoundary.clearReset();
68
+ defaultedOptions.onError == null ? void 0 : defaultedOptions.onError(error);
69
+ defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(undefined, error);
70
+ });
71
+ } // Handle error boundary
72
+
73
+
74
+ if (result.isError && !errorResetBoundary.isReset() && !result.isFetching && shouldThrowError(defaultedOptions.useErrorBoundary, [result.error, observer.getCurrentQuery()])) {
75
+ throw result.error;
76
+ } // Handle result property usage tracking
77
+
78
+
79
+ return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
80
+ }
81
+
82
+ export { useBaseQuery };
83
+ //# sourceMappingURL=useBaseQuery.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBaseQuery.esm.js","sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import * as React from 'react'\nimport { useSyncExternalStore } from './useSyncExternalStore'\n\nimport { QueryKey, notifyManager, QueryObserver } from '@tanstack/query-core'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport { useQueryClient } from './QueryClientProvider'\nimport { UseBaseQueryOptions } from './types'\nimport { shouldThrowError } from './utils'\nimport { useIsRestoring } from './isRestoring'\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: UseBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n) {\n const queryClient = useQueryClient({ context: options.context })\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const defaultedOptions = queryClient.defaultQueryOptions(options)\n\n // Make sure results are optimistically set in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : 'optimistic'\n\n // Include callbacks in batch renders\n if (defaultedOptions.onError) {\n defaultedOptions.onError = notifyManager.batchCalls(\n defaultedOptions.onError,\n )\n }\n\n if (defaultedOptions.onSuccess) {\n defaultedOptions.onSuccess = notifyManager.batchCalls(\n defaultedOptions.onSuccess,\n )\n }\n\n if (defaultedOptions.onSettled) {\n defaultedOptions.onSettled = notifyManager.batchCalls(\n defaultedOptions.onSettled,\n )\n }\n\n if (defaultedOptions.suspense) {\n // Always set stale time when using suspense to prevent\n // fetching again when directly mounting after suspending\n if (typeof defaultedOptions.staleTime !== 'number') {\n defaultedOptions.staleTime = 1000\n }\n }\n\n if (defaultedOptions.suspense || defaultedOptions.useErrorBoundary) {\n // Prevent retrying failed query if the error boundary has not been reset yet\n if (!errorResetBoundary.isReset()) {\n defaultedOptions.retryOnMount = false\n }\n }\n\n const [observer] = React.useState(\n () =>\n new Observer<TQueryFnData, TError, TData, TQueryData, TQueryKey>(\n queryClient,\n defaultedOptions,\n ),\n )\n\n const result = observer.getOptimisticResult(defaultedOptions)\n\n useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n isRestoring\n ? () => undefined\n : observer.subscribe(notifyManager.batchCalls(onStoreChange)),\n [observer, isRestoring],\n ),\n () => observer.getCurrentResult(),\n () => observer.getCurrentResult(),\n )\n\n React.useEffect(() => {\n errorResetBoundary.clearReset()\n }, [errorResetBoundary])\n\n React.useEffect(() => {\n // Do not notify on updates because of changes in the options because\n // these changes should already be reflected in the optimistic result.\n observer.setOptions(defaultedOptions, { listeners: false })\n }, [defaultedOptions, observer])\n\n // Handle suspense\n if (\n defaultedOptions.suspense &&\n result.isLoading &&\n result.isFetching &&\n !isRestoring\n ) {\n throw observer\n .fetchOptimistic(defaultedOptions)\n .then(({ data }) => {\n defaultedOptions.onSuccess?.(data as TData)\n defaultedOptions.onSettled?.(data, null)\n })\n .catch((error) => {\n errorResetBoundary.clearReset()\n defaultedOptions.onError?.(error)\n defaultedOptions.onSettled?.(undefined, error)\n })\n }\n\n // Handle error boundary\n if (\n result.isError &&\n !errorResetBoundary.isReset() &&\n !result.isFetching &&\n shouldThrowError(defaultedOptions.useErrorBoundary, [\n result.error,\n observer.getCurrentQuery(),\n ])\n ) {\n throw result.error\n }\n\n // Handle result property usage tracking\n return !defaultedOptions.notifyOnChangeProps\n ? observer.trackResult(result)\n : result\n}\n"],"names":["useBaseQuery","options","Observer","queryClient","useQueryClient","context","isRestoring","useIsRestoring","errorResetBoundary","useQueryErrorResetBoundary","defaultedOptions","defaultQueryOptions","_optimisticResults","onError","notifyManager","batchCalls","onSuccess","onSettled","suspense","staleTime","useErrorBoundary","isReset","retryOnMount","observer","React","useState","result","getOptimisticResult","useSyncExternalStore","useCallback","onStoreChange","undefined","subscribe","getCurrentResult","useEffect","clearReset","setOptions","listeners","isLoading","isFetching","fetchOptimistic","then","data","catch","error","isError","shouldThrowError","getCurrentQuery","notifyOnChangeProps","trackResult"],"mappings":"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"}
@@ -0,0 +1,10 @@
1
+ import { parseQueryArgs, InfiniteQueryObserver } from '@tanstack/query-core';
2
+ import { useBaseQuery } from './useBaseQuery.esm.js';
3
+
4
+ function useInfiniteQuery(arg1, arg2, arg3) {
5
+ const options = parseQueryArgs(arg1, arg2, arg3);
6
+ return useBaseQuery(options, InfiniteQueryObserver);
7
+ }
8
+
9
+ export { useInfiniteQuery };
10
+ //# sourceMappingURL=useInfiniteQuery.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInfiniteQuery.esm.js","sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import {\n QueryObserver,\n InfiniteQueryObserver,\n QueryFunction,\n QueryKey,\n parseQueryArgs,\n} from '@tanstack/query-core'\nimport { UseInfiniteQueryOptions, UseInfiniteQueryResult } from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\n// HOOK\n\nexport function useInfiniteQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n >,\n): UseInfiniteQueryResult<TData, TError>\nexport function useInfiniteQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n options?: Omit<\n UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n >,\n 'queryKey'\n >,\n): UseInfiniteQueryResult<TData, TError>\nexport function useInfiniteQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n queryFn: QueryFunction<TQueryFnData, TQueryKey>,\n options?: Omit<\n UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n >,\n 'queryKey' | 'queryFn'\n >,\n): UseInfiniteQueryResult<TData, TError>\nexport function useInfiniteQuery<\n TQueryFnData,\n TError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n arg1:\n | TQueryKey\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n >,\n arg2?:\n | QueryFunction<TQueryFnData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n >,\n arg3?: UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n >,\n): UseInfiniteQueryResult<TData, TError> {\n const options = parseQueryArgs(arg1, arg2, arg3)\n return useBaseQuery(\n options,\n InfiniteQueryObserver as typeof QueryObserver,\n ) as UseInfiniteQueryResult<TData, TError>\n}\n"],"names":["useInfiniteQuery","arg1","arg2","arg3","options","parseQueryArgs","useBaseQuery","InfiniteQueryObserver"],"mappings":";;;AA+DO,SAASA,gBAAT,CAMLC,IANK,EAeLC,IAfK,EAwBLC,IAxBK,EA+BkC;EACvC,MAAMC,OAAO,GAAGC,cAAc,CAACJ,IAAD,EAAOC,IAAP,EAAaC,IAAb,CAA9B,CAAA;AACA,EAAA,OAAOG,YAAY,CACjBF,OADiB,EAEjBG,qBAFiB,CAAnB,CAAA;AAID;;;;"}
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ import { parseFilterArgs, notifyManager } from '@tanstack/query-core';
3
+ import { useQueryClient } from './QueryClientProvider.esm.js';
4
+ import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
5
+
6
+ function useIsFetching(arg1, arg2, arg3) {
7
+ const [filters, options = {}] = parseFilterArgs(arg1, arg2, arg3);
8
+ const queryClient = useQueryClient({
9
+ context: options.context
10
+ });
11
+ const queryCache = queryClient.getQueryCache();
12
+ return useSyncExternalStore(React.useCallback(onStoreChange => queryCache.subscribe(notifyManager.batchCalls(onStoreChange)), [queryCache]), () => queryClient.isFetching(filters), () => queryClient.isFetching(filters));
13
+ }
14
+
15
+ export { useIsFetching };
16
+ //# sourceMappingURL=useIsFetching.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIsFetching.esm.js","sources":["../../src/useIsFetching.ts"],"sourcesContent":["import * as React from 'react'\nimport {\n QueryKey,\n notifyManager,\n parseFilterArgs,\n QueryFilters,\n} from '@tanstack/query-core'\n\nimport { useSyncExternalStore } from './useSyncExternalStore'\nimport { ContextOptions } from './types'\nimport { useQueryClient } from './QueryClientProvider'\n\ninterface Options extends ContextOptions {}\n\nexport function useIsFetching(filters?: QueryFilters, options?: Options): number\nexport function useIsFetching(\n queryKey?: QueryKey,\n filters?: QueryFilters,\n options?: Options,\n): number\nexport function useIsFetching(\n arg1?: QueryKey | QueryFilters,\n arg2?: QueryFilters | Options,\n arg3?: Options,\n): number {\n const [filters, options = {}] = parseFilterArgs(arg1, arg2, arg3)\n const queryClient = useQueryClient({ context: options.context })\n const queryCache = queryClient.getQueryCache()\n\n return useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n queryCache.subscribe(notifyManager.batchCalls(onStoreChange)),\n [queryCache],\n ),\n () => queryClient.isFetching(filters),\n () => queryClient.isFetching(filters),\n )\n}\n"],"names":["useIsFetching","arg1","arg2","arg3","filters","options","parseFilterArgs","queryClient","useQueryClient","context","queryCache","getQueryCache","useSyncExternalStore","React","useCallback","onStoreChange","subscribe","notifyManager","batchCalls","isFetching"],"mappings":";;;;;AAoBO,SAASA,aAAT,CACLC,IADK,EAELC,IAFK,EAGLC,IAHK,EAIG;AACR,EAAA,MAAM,CAACC,OAAD,EAAUC,OAAO,GAAG,EAApB,CAAA,GAA0BC,eAAe,CAACL,IAAD,EAAOC,IAAP,EAAaC,IAAb,CAA/C,CAAA;EACA,MAAMI,WAAW,GAAGC,cAAc,CAAC;IAAEC,OAAO,EAAEJ,OAAO,CAACI,OAAAA;AAAnB,GAAD,CAAlC,CAAA;AACA,EAAA,MAAMC,UAAU,GAAGH,WAAW,CAACI,aAAZ,EAAnB,CAAA;AAEA,EAAA,OAAOC,oBAAoB,CACzBC,KAAK,CAACC,WAAN,CACGC,aAAD,IACEL,UAAU,CAACM,SAAX,CAAqBC,aAAa,CAACC,UAAd,CAAyBH,aAAzB,CAArB,CAFJ,EAGE,CAACL,UAAD,CAHF,CADyB,EAMzB,MAAMH,WAAW,CAACY,UAAZ,CAAuBf,OAAvB,CANmB,EAOzB,MAAMG,WAAW,CAACY,UAAZ,CAAuBf,OAAvB,CAPmB,CAA3B,CAAA;AASD;;;;"}
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ import { parseMutationFilterArgs, notifyManager } from '@tanstack/query-core';
3
+ import { useQueryClient } from './QueryClientProvider.esm.js';
4
+ import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
5
+
6
+ function useIsMutating(arg1, arg2, arg3) {
7
+ const [filters, options = {}] = parseMutationFilterArgs(arg1, arg2, arg3);
8
+ const queryClient = useQueryClient({
9
+ context: options.context
10
+ });
11
+ const mutationCache = queryClient.getMutationCache();
12
+ return useSyncExternalStore(React.useCallback(onStoreChange => mutationCache.subscribe(notifyManager.batchCalls(onStoreChange)), [mutationCache]), () => queryClient.isMutating(filters), () => queryClient.isMutating(filters));
13
+ }
14
+
15
+ export { useIsMutating };
16
+ //# sourceMappingURL=useIsMutating.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIsMutating.esm.js","sources":["../../src/useIsMutating.ts"],"sourcesContent":["import * as React from 'react'\nimport { useSyncExternalStore } from './useSyncExternalStore'\n\nimport {\n notifyManager,\n MutationKey,\n MutationFilters,\n parseMutationFilterArgs,\n} from '@tanstack/query-core'\nimport { ContextOptions } from './types'\nimport { useQueryClient } from './QueryClientProvider'\n\ninterface Options extends ContextOptions {}\n\nexport function useIsMutating(\n filters?: MutationFilters,\n options?: Options,\n): number\nexport function useIsMutating(\n mutationKey?: MutationKey,\n filters?: Omit<MutationFilters, 'mutationKey'>,\n options?: Options,\n): number\nexport function useIsMutating(\n arg1?: MutationKey | MutationFilters,\n arg2?: Omit<MutationFilters, 'mutationKey'> | Options,\n arg3?: Options,\n): number {\n const [filters, options = {}] = parseMutationFilterArgs(arg1, arg2, arg3)\n\n const queryClient = useQueryClient({ context: options.context })\n const mutationCache = queryClient.getMutationCache()\n\n return useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n mutationCache.subscribe(notifyManager.batchCalls(onStoreChange)),\n [mutationCache],\n ),\n () => queryClient.isMutating(filters),\n () => queryClient.isMutating(filters),\n )\n}\n"],"names":["useIsMutating","arg1","arg2","arg3","filters","options","parseMutationFilterArgs","queryClient","useQueryClient","context","mutationCache","getMutationCache","useSyncExternalStore","React","useCallback","onStoreChange","subscribe","notifyManager","batchCalls","isMutating"],"mappings":";;;;;AAuBO,SAASA,aAAT,CACLC,IADK,EAELC,IAFK,EAGLC,IAHK,EAIG;AACR,EAAA,MAAM,CAACC,OAAD,EAAUC,OAAO,GAAG,EAApB,CAAA,GAA0BC,uBAAuB,CAACL,IAAD,EAAOC,IAAP,EAAaC,IAAb,CAAvD,CAAA;EAEA,MAAMI,WAAW,GAAGC,cAAc,CAAC;IAAEC,OAAO,EAAEJ,OAAO,CAACI,OAAAA;AAAnB,GAAD,CAAlC,CAAA;AACA,EAAA,MAAMC,aAAa,GAAGH,WAAW,CAACI,gBAAZ,EAAtB,CAAA;AAEA,EAAA,OAAOC,oBAAoB,CACzBC,KAAK,CAACC,WAAN,CACGC,aAAD,IACEL,aAAa,CAACM,SAAd,CAAwBC,aAAa,CAACC,UAAd,CAAyBH,aAAzB,CAAxB,CAFJ,EAGE,CAACL,aAAD,CAHF,CADyB,EAMzB,MAAMH,WAAW,CAACY,UAAZ,CAAuBf,OAAvB,CANmB,EAOzB,MAAMG,WAAW,CAACY,UAAZ,CAAuBf,OAAvB,CAPmB,CAA3B,CAAA;AASD;;;;"}
@@ -0,0 +1,34 @@
1
+ import * as React from 'react';
2
+ import { parseMutationArgs, MutationObserver, notifyManager } from '@tanstack/query-core';
3
+ import { useQueryClient } from './QueryClientProvider.esm.js';
4
+ import { shouldThrowError } from './utils.esm.js';
5
+ import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
6
+
7
+ function useMutation(arg1, arg2, arg3) {
8
+ const options = parseMutationArgs(arg1, arg2, arg3);
9
+ const queryClient = useQueryClient({
10
+ context: options.context
11
+ });
12
+ const [observer] = React.useState(() => new MutationObserver(queryClient, options));
13
+ React.useEffect(() => {
14
+ observer.setOptions(options);
15
+ }, [observer, options]);
16
+ const result = useSyncExternalStore(React.useCallback(onStoreChange => observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
17
+ const mutate = React.useCallback((variables, mutateOptions) => {
18
+ observer.mutate(variables, mutateOptions).catch(noop);
19
+ }, [observer]);
20
+
21
+ if (result.error && shouldThrowError(observer.options.useErrorBoundary, [result.error])) {
22
+ throw result.error;
23
+ }
24
+
25
+ return { ...result,
26
+ mutate,
27
+ mutateAsync: result.mutate
28
+ };
29
+ } // eslint-disable-next-line @typescript-eslint/no-empty-function
30
+
31
+ function noop() {}
32
+
33
+ export { useMutation };
34
+ //# sourceMappingURL=useMutation.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMutation.esm.js","sources":["../../src/useMutation.ts"],"sourcesContent":["import * as React from 'react'\nimport { useSyncExternalStore } from './useSyncExternalStore'\n\nimport {\n notifyManager,\n parseMutationArgs,\n MutationObserver,\n MutationFunction,\n MutationKey,\n} from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport {\n UseMutateFunction,\n UseMutationOptions,\n UseMutationResult,\n} from './types'\nimport { shouldThrowError } from './utils'\n\n// HOOK\n\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TContext>,\n): UseMutationResult<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n mutationFn: MutationFunction<TData, TVariables>,\n options?: Omit<\n UseMutationOptions<TData, TError, TVariables, TContext>,\n 'mutationFn'\n >,\n): UseMutationResult<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n mutationKey: MutationKey,\n options?: Omit<\n UseMutationOptions<TData, TError, TVariables, TContext>,\n 'mutationKey'\n >,\n): UseMutationResult<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n mutationKey: MutationKey,\n mutationFn?: MutationFunction<TData, TVariables>,\n options?: Omit<\n UseMutationOptions<TData, TError, TVariables, TContext>,\n 'mutationKey' | 'mutationFn'\n >,\n): UseMutationResult<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n arg1:\n | MutationKey\n | MutationFunction<TData, TVariables>\n | UseMutationOptions<TData, TError, TVariables, TContext>,\n arg2?:\n | MutationFunction<TData, TVariables>\n | UseMutationOptions<TData, TError, TVariables, TContext>,\n arg3?: UseMutationOptions<TData, TError, TVariables, TContext>,\n): UseMutationResult<TData, TError, TVariables, TContext> {\n const options = parseMutationArgs(arg1, arg2, arg3)\n const queryClient = useQueryClient({ context: options.context })\n\n const [observer] = React.useState(\n () =>\n new MutationObserver<TData, TError, TVariables, TContext>(\n queryClient,\n options,\n ),\n )\n\n React.useEffect(() => {\n observer.setOptions(options)\n }, [observer, options])\n\n const result = useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n observer.subscribe(notifyManager.batchCalls(onStoreChange)),\n [observer],\n ),\n () => observer.getCurrentResult(),\n () => observer.getCurrentResult(),\n )\n\n const mutate = React.useCallback<\n UseMutateFunction<TData, TError, TVariables, TContext>\n >(\n (variables, mutateOptions) => {\n observer.mutate(variables, mutateOptions).catch(noop)\n },\n [observer],\n )\n\n if (\n result.error &&\n shouldThrowError(observer.options.useErrorBoundary, [result.error])\n ) {\n throw result.error\n }\n\n return { ...result, mutate, mutateAsync: result.mutate }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nfunction noop() {}\n"],"names":["useMutation","arg1","arg2","arg3","options","parseMutationArgs","queryClient","useQueryClient","context","observer","React","useState","MutationObserver","useEffect","setOptions","result","useSyncExternalStore","useCallback","onStoreChange","subscribe","notifyManager","batchCalls","getCurrentResult","mutate","variables","mutateOptions","catch","noop","error","shouldThrowError","useErrorBoundary","mutateAsync"],"mappings":";;;;;;AAiEO,SAASA,WAAT,CAMLC,IANK,EAULC,IAVK,EAaLC,IAbK,EAcmD;EACxD,MAAMC,OAAO,GAAGC,iBAAiB,CAACJ,IAAD,EAAOC,IAAP,EAAaC,IAAb,CAAjC,CAAA;EACA,MAAMG,WAAW,GAAGC,cAAc,CAAC;IAAEC,OAAO,EAAEJ,OAAO,CAACI,OAAAA;AAAnB,GAAD,CAAlC,CAAA;AAEA,EAAA,MAAM,CAACC,QAAD,CAAaC,GAAAA,KAAK,CAACC,QAAN,CACjB,MACE,IAAIC,gBAAJ,CACEN,WADF,EAEEF,OAFF,CAFe,CAAnB,CAAA;EAQAM,KAAK,CAACG,SAAN,CAAgB,MAAM;IACpBJ,QAAQ,CAACK,UAAT,CAAoBV,OAApB,CAAA,CAAA;AACD,GAFD,EAEG,CAACK,QAAD,EAAWL,OAAX,CAFH,CAAA,CAAA;AAIA,EAAA,MAAMW,MAAM,GAAGC,oBAAoB,CACjCN,KAAK,CAACO,WAAN,CACGC,aAAD,IACET,QAAQ,CAACU,SAAT,CAAmBC,aAAa,CAACC,UAAd,CAAyBH,aAAzB,CAAnB,CAFJ,EAGE,CAACT,QAAD,CAHF,CADiC,EAMjC,MAAMA,QAAQ,CAACa,gBAAT,EAN2B,EAOjC,MAAMb,QAAQ,CAACa,gBAAT,EAP2B,CAAnC,CAAA;EAUA,MAAMC,MAAM,GAAGb,KAAK,CAACO,WAAN,CAGb,CAACO,SAAD,EAAYC,aAAZ,KAA8B;IAC5BhB,QAAQ,CAACc,MAAT,CAAgBC,SAAhB,EAA2BC,aAA3B,CAAA,CAA0CC,KAA1C,CAAgDC,IAAhD,CAAA,CAAA;AACD,GALY,EAMb,CAAClB,QAAD,CANa,CAAf,CAAA;;AASA,EAAA,IACEM,MAAM,CAACa,KAAP,IACAC,gBAAgB,CAACpB,QAAQ,CAACL,OAAT,CAAiB0B,gBAAlB,EAAoC,CAACf,MAAM,CAACa,KAAR,CAApC,CAFlB,EAGE;IACA,MAAMb,MAAM,CAACa,KAAb,CAAA;AACD,GAAA;;EAED,OAAO,EAAE,GAAGb,MAAL;IAAaQ,MAAb;IAAqBQ,WAAW,EAAEhB,MAAM,CAACQ,MAAAA;GAAhD,CAAA;AACD;;AAGD,SAASI,IAAT,GAAgB;;;;"}
@@ -0,0 +1,37 @@
1
+ import * as React from 'react';
2
+ import { QueriesObserver, notifyManager } from '@tanstack/query-core';
3
+ import { useQueryClient } from './QueryClientProvider.esm.js';
4
+ import { useIsRestoring } from './isRestoring.esm.js';
5
+ import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
6
+
7
+ // - `context` is omitted as it is passed as a root-level option to `useQueries` instead.
8
+
9
+ function useQueries({
10
+ queries,
11
+ context
12
+ }) {
13
+ const queryClient = useQueryClient({
14
+ context
15
+ });
16
+ const isRestoring = useIsRestoring();
17
+ const defaultedQueries = React.useMemo(() => queries.map(options => {
18
+ const defaultedOptions = queryClient.defaultQueryOptions(options); // Make sure the results are already in fetching state before subscribing or updating options
19
+
20
+ defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic';
21
+ return defaultedOptions;
22
+ }), [queries, queryClient, isRestoring]);
23
+ const [observer] = React.useState(() => new QueriesObserver(queryClient, defaultedQueries));
24
+ const result = observer.getOptimisticResult(defaultedQueries);
25
+ useSyncExternalStore(React.useCallback(onStoreChange => isRestoring ? () => undefined : observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
26
+ React.useEffect(() => {
27
+ // Do not notify on updates because of changes in the options because
28
+ // these changes should already be reflected in the optimistic result.
29
+ observer.setQueries(defaultedQueries, {
30
+ listeners: false
31
+ });
32
+ }, [defaultedQueries, observer]);
33
+ return result;
34
+ }
35
+
36
+ export { useQueries };
37
+ //# sourceMappingURL=useQueries.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useQueries.esm.js","sources":["../../src/useQueries.ts"],"sourcesContent":["import * as React from 'react'\nimport { useSyncExternalStore } from './useSyncExternalStore'\n\nimport {\n QueryKey,\n QueryFunction,\n notifyManager,\n QueriesObserver,\n} from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport { UseQueryOptions, UseQueryResult } from './types'\nimport { useIsRestoring } from './isRestoring'\n\n// This defines the `UseQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.\n// - `context` is omitted as it is passed as a root-level option to `useQueries` instead.\ntype UseQueryOptionsForUseQueries<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'context'>\n\n// Avoid TS depth-limit error in case of large array literal\ntype MAXIMUM_DEPTH = 20\n\ntype GetOptions<T> =\n // Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }\n T extends {\n queryFnData: infer TQueryFnData\n error?: infer TError\n data: infer TData\n }\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseQueryOptionsForUseQueries<unknown, TError, TData>\n : // Part 2: responsible for applying explicit type parameter to function arguments, if tuple [TQueryFnData, TError, TData]\n T extends [infer TQueryFnData, infer TError, infer TData]\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData>\n : T extends [infer TQueryFnData, infer TError]\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseQueryOptionsForUseQueries<TQueryFnData>\n : // Part 3: responsible for inferring and enforcing type if no explicit parameter was provided\n T extends {\n queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey>\n select: (data: any) => infer TData\n }\n ? UseQueryOptionsForUseQueries<TQueryFnData, unknown, TData, TQueryKey>\n : T extends { queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey> }\n ? UseQueryOptionsForUseQueries<\n TQueryFnData,\n unknown,\n TQueryFnData,\n TQueryKey\n >\n : // Fallback\n UseQueryOptionsForUseQueries\n\ntype GetResults<T> =\n // Part 1: responsible for mapping explicit type parameter to function result, if object\n T extends { queryFnData: any; error?: infer TError; data: infer TData }\n ? UseQueryResult<TData, TError>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseQueryResult<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseQueryResult<TData, TError>\n : // Part 2: responsible for mapping explicit type parameter to function result, if tuple\n T extends [any, infer TError, infer TData]\n ? UseQueryResult<TData, TError>\n : T extends [infer TQueryFnData, infer TError]\n ? UseQueryResult<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseQueryResult<TQueryFnData>\n : // Part 3: responsible for mapping inferred type to results, if no explicit parameter was provided\n T extends {\n queryFn?: QueryFunction<unknown, any>\n select: (data: any) => infer TData\n }\n ? UseQueryResult<TData>\n : T extends { queryFn?: QueryFunction<infer TQueryFnData, any> }\n ? UseQueryResult<TQueryFnData>\n : // Fallback\n UseQueryResult\n\n/**\n * QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param\n */\nexport type QueriesOptions<\n T extends any[],\n Result extends any[] = [],\n Depth extends ReadonlyArray<number> = [],\n> = Depth['length'] extends MAXIMUM_DEPTH\n ? UseQueryOptionsForUseQueries[]\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...Result, GetOptions<Head>]\n : T extends [infer Head, ...infer Tail]\n ? QueriesOptions<[...Tail], [...Result, GetOptions<Head>], [...Depth, 1]>\n : unknown[] extends T\n ? T\n : // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogenous type!\n // use this to infer the param types in the case of Array.map() argument\n T extends UseQueryOptionsForUseQueries<\n infer TQueryFnData,\n infer TError,\n infer TData,\n infer TQueryKey\n >[]\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData, TQueryKey>[]\n : // Fallback\n UseQueryOptionsForUseQueries[]\n\n/**\n * QueriesResults reducer recursively maps type param to results\n */\nexport type QueriesResults<\n T extends any[],\n Result extends any[] = [],\n Depth extends ReadonlyArray<number> = [],\n> = Depth['length'] extends MAXIMUM_DEPTH\n ? UseQueryResult[]\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...Result, GetResults<Head>]\n : T extends [infer Head, ...infer Tail]\n ? QueriesResults<[...Tail], [...Result, GetResults<Head>], [...Depth, 1]>\n : T extends UseQueryOptionsForUseQueries<\n infer TQueryFnData,\n infer TError,\n infer TData,\n any\n >[]\n ? // Dynamic-size (homogenous) UseQueryOptions array: map directly to array of results\n UseQueryResult<unknown extends TData ? TQueryFnData : TData, TError>[]\n : // Fallback\n UseQueryResult[]\n\nexport function useQueries<T extends any[]>({\n queries,\n context,\n}: {\n queries: readonly [...QueriesOptions<T>]\n context?: UseQueryOptions['context']\n}): QueriesResults<T> {\n const queryClient = useQueryClient({ context })\n const isRestoring = useIsRestoring()\n\n const defaultedQueries = React.useMemo(\n () =>\n queries.map((options) => {\n const defaultedOptions = queryClient.defaultQueryOptions(options)\n\n // Make sure the results are already in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : 'optimistic'\n\n return defaultedOptions\n }),\n [queries, queryClient, isRestoring],\n )\n\n const [observer] = React.useState(\n () => new QueriesObserver(queryClient, defaultedQueries),\n )\n\n const result = observer.getOptimisticResult(defaultedQueries)\n\n useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n isRestoring\n ? () => undefined\n : observer.subscribe(notifyManager.batchCalls(onStoreChange)),\n [observer, isRestoring],\n ),\n () => observer.getCurrentResult(),\n () => observer.getCurrentResult(),\n )\n\n React.useEffect(() => {\n // Do not notify on updates because of changes in the options because\n // these changes should already be reflected in the optimistic result.\n observer.setQueries(defaultedQueries, { listeners: false })\n }, [defaultedQueries, observer])\n\n return result as QueriesResults<T>\n}\n"],"names":["useQueries","queries","context","queryClient","useQueryClient","isRestoring","useIsRestoring","defaultedQueries","React","useMemo","map","options","defaultedOptions","defaultQueryOptions","_optimisticResults","observer","useState","QueriesObserver","result","getOptimisticResult","useSyncExternalStore","useCallback","onStoreChange","undefined","subscribe","notifyManager","batchCalls","getCurrentResult","useEffect","setQueries","listeners"],"mappings":";;;;;;AAcA;;AA+HO,SAASA,UAAT,CAAqC;EAC1CC,OAD0C;AAE1CC,EAAAA,OAAAA;AAF0C,CAArC,EAMe;EACpB,MAAMC,WAAW,GAAGC,cAAc,CAAC;AAAEF,IAAAA,OAAAA;AAAF,GAAD,CAAlC,CAAA;EACA,MAAMG,WAAW,GAAGC,cAAc,EAAlC,CAAA;AAEA,EAAA,MAAMC,gBAAgB,GAAGC,KAAK,CAACC,OAAN,CACvB,MACER,OAAO,CAACS,GAAR,CAAaC,OAAD,IAAa;IACvB,MAAMC,gBAAgB,GAAGT,WAAW,CAACU,mBAAZ,CAAgCF,OAAhC,CAAzB,CADuB;;AAIvBC,IAAAA,gBAAgB,CAACE,kBAAjB,GAAsCT,WAAW,GAC7C,aAD6C,GAE7C,YAFJ,CAAA;AAIA,IAAA,OAAOO,gBAAP,CAAA;GARF,CAFqB,EAYvB,CAACX,OAAD,EAAUE,WAAV,EAAuBE,WAAvB,CAZuB,CAAzB,CAAA;AAeA,EAAA,MAAM,CAACU,QAAD,CAAaP,GAAAA,KAAK,CAACQ,QAAN,CACjB,MAAM,IAAIC,eAAJ,CAAoBd,WAApB,EAAiCI,gBAAjC,CADW,CAAnB,CAAA;AAIA,EAAA,MAAMW,MAAM,GAAGH,QAAQ,CAACI,mBAAT,CAA6BZ,gBAA7B,CAAf,CAAA;AAEAa,EAAAA,oBAAoB,CAClBZ,KAAK,CAACa,WAAN,CACGC,aAAD,IACEjB,WAAW,GACP,MAAMkB,SADC,GAEPR,QAAQ,CAACS,SAAT,CAAmBC,aAAa,CAACC,UAAd,CAAyBJ,aAAzB,CAAnB,CAJR,EAKE,CAACP,QAAD,EAAWV,WAAX,CALF,CADkB,EAQlB,MAAMU,QAAQ,CAACY,gBAAT,EARY,EASlB,MAAMZ,QAAQ,CAACY,gBAAT,EATY,CAApB,CAAA;EAYAnB,KAAK,CAACoB,SAAN,CAAgB,MAAM;AACpB;AACA;AACAb,IAAAA,QAAQ,CAACc,UAAT,CAAoBtB,gBAApB,EAAsC;AAAEuB,MAAAA,SAAS,EAAE,KAAA;KAAnD,CAAA,CAAA;AACD,GAJD,EAIG,CAACvB,gBAAD,EAAmBQ,QAAnB,CAJH,CAAA,CAAA;AAMA,EAAA,OAAOG,MAAP,CAAA;AACD;;;;"}
@@ -0,0 +1,10 @@
1
+ import { parseQueryArgs, QueryObserver } from '@tanstack/query-core';
2
+ import { useBaseQuery } from './useBaseQuery.esm.js';
3
+
4
+ function useQuery(arg1, arg2, arg3) {
5
+ const parsedOptions = parseQueryArgs(arg1, arg2, arg3);
6
+ return useBaseQuery(parsedOptions, QueryObserver);
7
+ }
8
+
9
+ export { useQuery };
10
+ //# sourceMappingURL=useQuery.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useQuery.esm.js","sources":["../../src/useQuery.ts"],"sourcesContent":["import {\n parseQueryArgs,\n QueryFunction,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport { DefinedUseQueryResult, UseQueryOptions, UseQueryResult } from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\n// HOOK\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'initialData'\n > & { initialData?: () => undefined },\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'initialData'\n > & { initialData: TQueryFnData | (() => TQueryFnData) },\n): DefinedUseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey' | 'initialData'\n > & { initialData?: () => undefined },\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey' | 'initialData'\n > & { initialData: TQueryFnData | (() => TQueryFnData) },\n): DefinedUseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey'\n >,\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n queryFn: QueryFunction<TQueryFnData, TQueryKey>,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey' | 'queryFn' | 'initialData'\n > & { initialData?: () => undefined },\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n queryFn: QueryFunction<TQueryFnData, TQueryKey>,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey' | 'queryFn' | 'initialData'\n > & { initialData: TQueryFnData | (() => TQueryFnData) },\n): DefinedUseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n queryFn: QueryFunction<TQueryFnData, TQueryKey>,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey' | 'queryFn'\n >,\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData,\n TError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n arg1: TQueryKey | UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n arg2?:\n | QueryFunction<TQueryFnData, TQueryKey>\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n arg3?: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UseQueryResult<TData, TError> {\n const parsedOptions = parseQueryArgs(arg1, arg2, arg3)\n return useBaseQuery(parsedOptions, QueryObserver)\n}\n"],"names":["useQuery","arg1","arg2","arg3","parsedOptions","parseQueryArgs","useBaseQuery","QueryObserver"],"mappings":";;;AA6HO,SAASA,QAAT,CAMLC,IANK,EAOLC,IAPK,EAULC,IAVK,EAW0B;EAC/B,MAAMC,aAAa,GAAGC,cAAc,CAACJ,IAAD,EAAOC,IAAP,EAAaC,IAAb,CAApC,CAAA;AACA,EAAA,OAAOG,YAAY,CAACF,aAAD,EAAgBG,aAAhB,CAAnB,CAAA;AACD;;;;"}
@@ -0,0 +1,11 @@
1
+ function shouldThrowError(_useErrorBoundary, params) {
2
+ // Allow useErrorBoundary function to override throwing behavior on a per-error basis
3
+ if (typeof _useErrorBoundary === 'function') {
4
+ return _useErrorBoundary(...params);
5
+ }
6
+
7
+ return !!_useErrorBoundary;
8
+ }
9
+
10
+ export { shouldThrowError };
11
+ //# sourceMappingURL=utils.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.esm.js","sources":["../../src/utils.ts"],"sourcesContent":["export function shouldThrowError<T extends (...args: any[]) => boolean>(\n _useErrorBoundary: boolean | T | undefined,\n params: Parameters<T>,\n): boolean {\n // Allow useErrorBoundary function to override throwing behavior on a per-error basis\n if (typeof _useErrorBoundary === 'function') {\n return _useErrorBoundary(...params)\n }\n\n return !!_useErrorBoundary\n}\n"],"names":["shouldThrowError","_useErrorBoundary","params"],"mappings":"AAAO,SAASA,gBAAT,CACLC,iBADK,EAELC,MAFK,EAGI;AACT;AACA,EAAA,IAAI,OAAOD,iBAAP,KAA6B,UAAjC,EAA6C;AAC3C,IAAA,OAAOA,iBAAiB,CAAC,GAAGC,MAAJ,CAAxB,CAAA;AACD,GAAA;;EAED,OAAO,CAAC,CAACD,iBAAT,CAAA;AACD;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-query",
3
- "version": "4.3.6",
3
+ "version": "4.3.8",
4
4
  "description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -12,6 +12,7 @@
12
12
  },
13
13
  "types": "build/lib/index.d.ts",
14
14
  "main": "build/lib/index.js",
15
+ "module": "build/lib/index.esm.js",
15
16
  "exports": {
16
17
  ".": {
17
18
  "types": "./build/lib/index.d.ts",
@@ -46,7 +47,7 @@
46
47
  "react-error-boundary": "^3.1.4"
47
48
  },
48
49
  "dependencies": {
49
- "@tanstack/query-core": "4.3.6",
50
+ "@tanstack/query-core": "4.3.8",
50
51
  "use-sync-external-store": "^1.2.0"
51
52
  },
52
53
  "peerDependencies": {