@tanstack/react-query 5.0.0-alpha.50 → 5.0.0-alpha.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/HydrationBoundary.cjs +50 -0
- package/build/lib/{HydrationBoundary.mjs.map → HydrationBoundary.cjs.map} +1 -1
- package/build/lib/HydrationBoundary.js +8 -29
- package/build/lib/HydrationBoundary.js.map +1 -1
- package/build/lib/QueryClientProvider.cjs +54 -0
- package/build/lib/{QueryClientProvider.mjs.map → QueryClientProvider.cjs.map} +1 -1
- package/build/lib/QueryClientProvider.js +6 -29
- package/build/lib/QueryClientProvider.js.map +1 -1
- package/build/lib/QueryErrorResetBoundary.cjs +60 -0
- package/build/lib/{QueryErrorResetBoundary.mjs.map → QueryErrorResetBoundary.cjs.map} +1 -1
- package/build/lib/QueryErrorResetBoundary.js +6 -28
- package/build/lib/QueryErrorResetBoundary.js.map +1 -1
- package/build/lib/errorBoundaryUtils.cjs +51 -0
- package/build/lib/{errorBoundaryUtils.mjs.map → errorBoundaryUtils.cjs.map} +1 -1
- package/build/lib/errorBoundaryUtils.js +5 -28
- package/build/lib/errorBoundaryUtils.js.map +1 -1
- package/build/lib/index.cjs +39 -0
- package/build/lib/index.cjs.map +1 -0
- package/build/lib/index.js +11 -38
- package/build/lib/index.js.map +1 -1
- package/build/lib/isRestoring.cjs +31 -0
- package/build/lib/{isRestoring.mjs.map → isRestoring.cjs.map} +1 -1
- package/build/lib/isRestoring.js +4 -26
- package/build/lib/isRestoring.js.map +1 -1
- package/build/lib/{suspense.mjs → suspense.cjs} +7 -2
- package/build/lib/{suspense.mjs.map → suspense.cjs.map} +1 -1
- package/build/lib/suspense.js +1 -6
- package/build/lib/suspense.js.map +1 -1
- package/build/lib/useBaseQuery.cjs +73 -0
- package/build/lib/{useBaseQuery.mjs.map → useBaseQuery.cjs.map} +1 -1
- package/build/lib/useBaseQuery.js +21 -42
- package/build/lib/useBaseQuery.js.map +1 -1
- package/build/lib/useInfiniteQuery.cjs +15 -0
- package/build/lib/{useInfiniteQuery.mjs.map → useInfiniteQuery.cjs.map} +1 -1
- package/build/lib/useInfiniteQuery.js +5 -7
- package/build/lib/useInfiniteQuery.js.map +1 -1
- package/build/lib/useIsFetching.cjs +34 -0
- package/build/lib/{useIsFetching.mjs.map → useIsFetching.cjs.map} +1 -1
- package/build/lib/useIsFetching.js +6 -27
- package/build/lib/useIsFetching.js.map +1 -1
- package/build/lib/useMutation.cjs +54 -0
- package/build/lib/{useMutation.mjs.map → useMutation.cjs.map} +1 -1
- package/build/lib/useMutation.js +11 -32
- package/build/lib/useMutation.js.map +1 -1
- package/build/lib/useMutationState.cjs +60 -0
- package/build/lib/{useMutationState.mjs.map → useMutationState.cjs.map} +1 -1
- package/build/lib/useMutationState.js +12 -34
- package/build/lib/useMutationState.js.map +1 -1
- package/build/lib/useQueries.cjs +99 -0
- package/build/lib/{useQueries.mjs.map → useQueries.cjs.map} +1 -1
- package/build/lib/useQueries.js +26 -47
- package/build/lib/useQueries.js.map +1 -1
- package/build/lib/useQuery.cjs +19 -0
- package/build/lib/{useQuery.mjs.map → useQuery.cjs.map} +1 -1
- package/build/lib/useQuery.js +4 -7
- package/build/lib/useQuery.js.map +1 -1
- package/build/lib/{utils.mjs → utils.cjs} +4 -2
- package/build/lib/{utils.mjs.map → utils.cjs.map} +1 -1
- package/build/lib/utils.js +1 -3
- package/build/lib/utils.js.map +1 -1
- package/package.json +8 -7
- package/build/lib/HydrationBoundary.mjs +0 -29
- package/build/lib/QueryClientProvider.mjs +0 -31
- package/build/lib/QueryErrorResetBoundary.mjs +0 -38
- package/build/lib/errorBoundaryUtils.mjs +0 -28
- package/build/lib/index.mjs +0 -12
- package/build/lib/index.mjs.map +0 -1
- package/build/lib/isRestoring.mjs +0 -9
- package/build/lib/useBaseQuery.mjs +0 -52
- package/build/lib/useInfiniteQuery.mjs +0 -13
- package/build/lib/useIsFetching.mjs +0 -13
- package/build/lib/useMutation.mjs +0 -33
- package/build/lib/useMutationState.mjs +0 -38
- package/build/lib/useQueries.mjs +0 -78
- package/build/lib/useQuery.mjs +0 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-query",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.51",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,15 +10,16 @@
|
|
|
10
10
|
"type": "github",
|
|
11
11
|
"url": "https://github.com/sponsors/tannerlinsley"
|
|
12
12
|
},
|
|
13
|
-
"type": "
|
|
13
|
+
"type": "module",
|
|
14
14
|
"types": "build/lib/index.d.ts",
|
|
15
|
-
"main": "build/lib/index.
|
|
16
|
-
"module": "build/lib/index.
|
|
15
|
+
"main": "build/lib/index.cjs",
|
|
16
|
+
"module": "build/lib/index.js",
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
19
|
"types": "./build/lib/index.d.ts",
|
|
20
|
-
"import": "./build/lib/index.
|
|
21
|
-
"
|
|
20
|
+
"import": "./build/lib/index.js",
|
|
21
|
+
"require": "./build/lib/index.cjs",
|
|
22
|
+
"default": "./build/lib/index.cjs"
|
|
22
23
|
},
|
|
23
24
|
"./package.json": "./package.json"
|
|
24
25
|
},
|
|
@@ -61,7 +62,7 @@
|
|
|
61
62
|
"test:lib": "vitest run --coverage",
|
|
62
63
|
"test:lib:dev": "pnpm run test:lib --watch",
|
|
63
64
|
"build": "pnpm build:rollup && pnpm build:codemods && pnpm build:types",
|
|
64
|
-
"build:rollup": "rollup --config rollup.config.
|
|
65
|
+
"build:rollup": "rollup --config rollup.config.js",
|
|
65
66
|
"build:codemods": "cpy ../codemods/src/**/* ./build/codemods",
|
|
66
67
|
"build:types": "tsc --emitDeclarationOnly"
|
|
67
68
|
}
|
|
@@ -1,29 +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
|
-
const HydrationBoundary = ({
|
|
7
|
-
children,
|
|
8
|
-
options = {},
|
|
9
|
-
state,
|
|
10
|
-
queryClient
|
|
11
|
-
}) => {
|
|
12
|
-
const client = useQueryClient(queryClient);
|
|
13
|
-
const optionsRef = React.useRef(options);
|
|
14
|
-
optionsRef.current = options;
|
|
15
|
-
|
|
16
|
-
// Running hydrate again with the same queries is safe,
|
|
17
|
-
// it wont overwrite or initialize existing queries,
|
|
18
|
-
// relying on useMemo here is only a performance optimization.
|
|
19
|
-
// hydrate can and should be run *during* render here for SSR to work properly
|
|
20
|
-
React.useMemo(() => {
|
|
21
|
-
if (state) {
|
|
22
|
-
hydrate(client, state, optionsRef.current);
|
|
23
|
-
}
|
|
24
|
-
}, [client, state]);
|
|
25
|
-
return children;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { HydrationBoundary };
|
|
29
|
-
//# sourceMappingURL=HydrationBoundary.mjs.map
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
const QueryClientContext = /*#__PURE__*/React.createContext(undefined);
|
|
5
|
-
const useQueryClient = queryClient => {
|
|
6
|
-
const client = React.useContext(QueryClientContext);
|
|
7
|
-
if (queryClient) {
|
|
8
|
-
return queryClient;
|
|
9
|
-
}
|
|
10
|
-
if (!client) {
|
|
11
|
-
throw new Error('No QueryClient set, use QueryClientProvider to set one');
|
|
12
|
-
}
|
|
13
|
-
return client;
|
|
14
|
-
};
|
|
15
|
-
const QueryClientProvider = ({
|
|
16
|
-
client,
|
|
17
|
-
children
|
|
18
|
-
}) => {
|
|
19
|
-
React.useEffect(() => {
|
|
20
|
-
client.mount();
|
|
21
|
-
return () => {
|
|
22
|
-
client.unmount();
|
|
23
|
-
};
|
|
24
|
-
}, [client]);
|
|
25
|
-
return /*#__PURE__*/React.createElement(QueryClientContext.Provider, {
|
|
26
|
-
value: client
|
|
27
|
-
}, children);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export { QueryClientContext, QueryClientProvider, useQueryClient };
|
|
31
|
-
//# sourceMappingURL=QueryClientProvider.mjs.map
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
// CONTEXT
|
|
5
|
-
|
|
6
|
-
function createValue() {
|
|
7
|
-
let isReset = false;
|
|
8
|
-
return {
|
|
9
|
-
clearReset: () => {
|
|
10
|
-
isReset = false;
|
|
11
|
-
},
|
|
12
|
-
reset: () => {
|
|
13
|
-
isReset = true;
|
|
14
|
-
},
|
|
15
|
-
isReset: () => {
|
|
16
|
-
return isReset;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
const QueryErrorResetBoundaryContext = /*#__PURE__*/React.createContext(createValue());
|
|
21
|
-
|
|
22
|
-
// HOOK
|
|
23
|
-
|
|
24
|
-
const useQueryErrorResetBoundary = () => React.useContext(QueryErrorResetBoundaryContext);
|
|
25
|
-
|
|
26
|
-
// COMPONENT
|
|
27
|
-
|
|
28
|
-
const QueryErrorResetBoundary = ({
|
|
29
|
-
children
|
|
30
|
-
}) => {
|
|
31
|
-
const [value] = React.useState(() => createValue());
|
|
32
|
-
return /*#__PURE__*/React.createElement(QueryErrorResetBoundaryContext.Provider, {
|
|
33
|
-
value: value
|
|
34
|
-
}, typeof children === 'function' ? children(value) : children);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export { QueryErrorResetBoundary, useQueryErrorResetBoundary };
|
|
38
|
-
//# sourceMappingURL=QueryErrorResetBoundary.mjs.map
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { shouldThrowError } from './utils.mjs';
|
|
4
|
-
|
|
5
|
-
const ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
|
|
6
|
-
if (options.suspense || options.throwOnError) {
|
|
7
|
-
// Prevent retrying failed query if the error boundary has not been reset yet
|
|
8
|
-
if (!errorResetBoundary.isReset()) {
|
|
9
|
-
options.retryOnMount = false;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
const useClearResetErrorBoundary = errorResetBoundary => {
|
|
14
|
-
React.useEffect(() => {
|
|
15
|
-
errorResetBoundary.clearReset();
|
|
16
|
-
}, [errorResetBoundary]);
|
|
17
|
-
};
|
|
18
|
-
const getHasError = ({
|
|
19
|
-
result,
|
|
20
|
-
errorResetBoundary,
|
|
21
|
-
throwOnError,
|
|
22
|
-
query
|
|
23
|
-
}) => {
|
|
24
|
-
return result.isError && !errorResetBoundary.isReset() && !result.isFetching && shouldThrowError(throwOnError, [result.error, query]);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export { ensurePreventErrorBoundaryRetry, getHasError, useClearResetErrorBoundary };
|
|
28
|
-
//# sourceMappingURL=errorBoundaryUtils.mjs.map
|
package/build/lib/index.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from '@tanstack/query-core';
|
|
2
|
-
export { useQueries } from './useQueries.mjs';
|
|
3
|
-
export { queryOptions, useQuery } from './useQuery.mjs';
|
|
4
|
-
export { QueryClientContext, QueryClientProvider, useQueryClient } from './QueryClientProvider.mjs';
|
|
5
|
-
export { HydrationBoundary } from './HydrationBoundary.mjs';
|
|
6
|
-
export { QueryErrorResetBoundary, useQueryErrorResetBoundary } from './QueryErrorResetBoundary.mjs';
|
|
7
|
-
export { useIsFetching } from './useIsFetching.mjs';
|
|
8
|
-
export { useIsMutating, useMutationState } from './useMutationState.mjs';
|
|
9
|
-
export { useMutation } from './useMutation.mjs';
|
|
10
|
-
export { useInfiniteQuery } from './useInfiniteQuery.mjs';
|
|
11
|
-
export { IsRestoringProvider, useIsRestoring } from './isRestoring.mjs';
|
|
12
|
-
//# sourceMappingURL=index.mjs.map
|
package/build/lib/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
const IsRestoringContext = /*#__PURE__*/React.createContext(false);
|
|
5
|
-
const useIsRestoring = () => React.useContext(IsRestoringContext);
|
|
6
|
-
const IsRestoringProvider = IsRestoringContext.Provider;
|
|
7
|
-
|
|
8
|
-
export { IsRestoringProvider, useIsRestoring };
|
|
9
|
-
//# sourceMappingURL=isRestoring.mjs.map
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { notifyManager } from '@tanstack/query-core';
|
|
4
|
-
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary.mjs';
|
|
5
|
-
import { useQueryClient } from './QueryClientProvider.mjs';
|
|
6
|
-
import { useIsRestoring } from './isRestoring.mjs';
|
|
7
|
-
import { ensurePreventErrorBoundaryRetry, useClearResetErrorBoundary, getHasError } from './errorBoundaryUtils.mjs';
|
|
8
|
-
import { ensureStaleTime, shouldSuspend, fetchOptimistic } from './suspense.mjs';
|
|
9
|
-
|
|
10
|
-
function useBaseQuery(options, Observer, queryClient) {
|
|
11
|
-
const client = useQueryClient(queryClient);
|
|
12
|
-
const isRestoring = useIsRestoring();
|
|
13
|
-
const errorResetBoundary = useQueryErrorResetBoundary();
|
|
14
|
-
const defaultedOptions = client.defaultQueryOptions(options);
|
|
15
|
-
|
|
16
|
-
// Make sure results are optimistically set in fetching state before subscribing or updating options
|
|
17
|
-
defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic';
|
|
18
|
-
ensureStaleTime(defaultedOptions);
|
|
19
|
-
ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary);
|
|
20
|
-
useClearResetErrorBoundary(errorResetBoundary);
|
|
21
|
-
const [observer] = React.useState(() => new Observer(client, defaultedOptions));
|
|
22
|
-
const result = observer.getOptimisticResult(defaultedOptions);
|
|
23
|
-
React.useSyncExternalStore(React.useCallback(onStoreChange => isRestoring ? () => undefined : observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
24
|
-
React.useEffect(() => {
|
|
25
|
-
// Do not notify on updates because of changes in the options because
|
|
26
|
-
// these changes should already be reflected in the optimistic result.
|
|
27
|
-
observer.setOptions(defaultedOptions, {
|
|
28
|
-
listeners: false
|
|
29
|
-
});
|
|
30
|
-
}, [defaultedOptions, observer]);
|
|
31
|
-
|
|
32
|
-
// Handle suspense
|
|
33
|
-
if (shouldSuspend(defaultedOptions, result, isRestoring)) {
|
|
34
|
-
throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Handle error boundary
|
|
38
|
-
if (getHasError({
|
|
39
|
-
result,
|
|
40
|
-
errorResetBoundary,
|
|
41
|
-
throwOnError: defaultedOptions.throwOnError,
|
|
42
|
-
query: observer.getCurrentQuery()
|
|
43
|
-
})) {
|
|
44
|
-
throw result.error;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Handle result property usage tracking
|
|
48
|
-
return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export { useBaseQuery };
|
|
52
|
-
//# sourceMappingURL=useBaseQuery.mjs.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { InfiniteQueryObserver } from '@tanstack/query-core';
|
|
3
|
-
import { useBaseQuery } from './useBaseQuery.mjs';
|
|
4
|
-
|
|
5
|
-
// HOOK
|
|
6
|
-
function useInfiniteQuery(options, queryClient) {
|
|
7
|
-
return useBaseQuery(options,
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
9
|
-
InfiniteQueryObserver, queryClient);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { useInfiniteQuery };
|
|
13
|
-
//# sourceMappingURL=useInfiniteQuery.mjs.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { notifyManager } from '@tanstack/query-core';
|
|
4
|
-
import { useQueryClient } from './QueryClientProvider.mjs';
|
|
5
|
-
|
|
6
|
-
function useIsFetching(filters, queryClient) {
|
|
7
|
-
const client = useQueryClient(queryClient);
|
|
8
|
-
const queryCache = client.getQueryCache();
|
|
9
|
-
return React.useSyncExternalStore(React.useCallback(onStoreChange => queryCache.subscribe(notifyManager.batchCalls(onStoreChange)), [queryCache]), () => client.isFetching(filters), () => client.isFetching(filters));
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { useIsFetching };
|
|
13
|
-
//# sourceMappingURL=useIsFetching.mjs.map
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { MutationObserver, notifyManager } from '@tanstack/query-core';
|
|
4
|
-
import { useQueryClient } from './QueryClientProvider.mjs';
|
|
5
|
-
import { shouldThrowError } from './utils.mjs';
|
|
6
|
-
|
|
7
|
-
// HOOK
|
|
8
|
-
|
|
9
|
-
function useMutation(options, queryClient) {
|
|
10
|
-
const client = useQueryClient(queryClient);
|
|
11
|
-
const [observer] = React.useState(() => new MutationObserver(client, options));
|
|
12
|
-
React.useEffect(() => {
|
|
13
|
-
observer.setOptions(options);
|
|
14
|
-
}, [observer, options]);
|
|
15
|
-
const result = React.useSyncExternalStore(React.useCallback(onStoreChange => observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
16
|
-
const mutate = React.useCallback((variables, mutateOptions) => {
|
|
17
|
-
observer.mutate(variables, mutateOptions).catch(noop);
|
|
18
|
-
}, [observer]);
|
|
19
|
-
if (result.error && shouldThrowError(observer.options.throwOnError, [result.error])) {
|
|
20
|
-
throw result.error;
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
...result,
|
|
24
|
-
mutate,
|
|
25
|
-
mutateAsync: result.mutate
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
30
|
-
function noop() {}
|
|
31
|
-
|
|
32
|
-
export { useMutation };
|
|
33
|
-
//# sourceMappingURL=useMutation.mjs.map
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { replaceEqualDeep, notifyManager } from '@tanstack/query-core';
|
|
4
|
-
import { useQueryClient } from './QueryClientProvider.mjs';
|
|
5
|
-
|
|
6
|
-
function useIsMutating(filters, queryClient) {
|
|
7
|
-
const client = useQueryClient(queryClient);
|
|
8
|
-
return useMutationState({
|
|
9
|
-
filters: {
|
|
10
|
-
...filters,
|
|
11
|
-
status: 'pending'
|
|
12
|
-
}
|
|
13
|
-
}, client).length;
|
|
14
|
-
}
|
|
15
|
-
function getResult(mutationCache, options) {
|
|
16
|
-
return mutationCache.findAll(options.filters).map(mutation => options.select ? options.select(mutation) : mutation.state);
|
|
17
|
-
}
|
|
18
|
-
function useMutationState(options = {}, queryClient) {
|
|
19
|
-
const mutationCache = useQueryClient(queryClient).getMutationCache();
|
|
20
|
-
const optionsRef = React.useRef(options);
|
|
21
|
-
const result = React.useRef();
|
|
22
|
-
if (!result.current) {
|
|
23
|
-
result.current = getResult(mutationCache, options);
|
|
24
|
-
}
|
|
25
|
-
React.useEffect(() => {
|
|
26
|
-
optionsRef.current = options;
|
|
27
|
-
});
|
|
28
|
-
return React.useSyncExternalStore(React.useCallback(onStoreChange => mutationCache.subscribe(() => {
|
|
29
|
-
const nextResult = replaceEqualDeep(result.current, getResult(mutationCache, optionsRef.current));
|
|
30
|
-
if (result.current !== nextResult) {
|
|
31
|
-
result.current = nextResult;
|
|
32
|
-
notifyManager.schedule(onStoreChange);
|
|
33
|
-
}
|
|
34
|
-
}), [mutationCache]), () => result.current, () => result.current);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export { useIsMutating, useMutationState };
|
|
38
|
-
//# sourceMappingURL=useMutationState.mjs.map
|
package/build/lib/useQueries.mjs
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { QueriesObserver, notifyManager } from '@tanstack/query-core';
|
|
4
|
-
import { useQueryClient } from './QueryClientProvider.mjs';
|
|
5
|
-
import { useIsRestoring } from './isRestoring.mjs';
|
|
6
|
-
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary.mjs';
|
|
7
|
-
import { ensurePreventErrorBoundaryRetry, useClearResetErrorBoundary, getHasError } from './errorBoundaryUtils.mjs';
|
|
8
|
-
import { ensureStaleTime, shouldSuspend, fetchOptimistic, willFetch } from './suspense.mjs';
|
|
9
|
-
|
|
10
|
-
// This defines the `UseQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.
|
|
11
|
-
// `placeholderData` function does not have a parameter
|
|
12
|
-
// Avoid TS depth-limit error in case of large array literal
|
|
13
|
-
/**
|
|
14
|
-
* QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* QueriesResults reducer recursively maps type param to results
|
|
18
|
-
*/
|
|
19
|
-
function useQueries({
|
|
20
|
-
queries,
|
|
21
|
-
...options
|
|
22
|
-
}, queryClient) {
|
|
23
|
-
const client = useQueryClient(queryClient);
|
|
24
|
-
const isRestoring = useIsRestoring();
|
|
25
|
-
const errorResetBoundary = useQueryErrorResetBoundary();
|
|
26
|
-
const defaultedQueries = React.useMemo(() => queries.map(opts => {
|
|
27
|
-
const defaultedOptions = client.defaultQueryOptions(opts);
|
|
28
|
-
|
|
29
|
-
// Make sure the results are already in fetching state before subscribing or updating options
|
|
30
|
-
defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic';
|
|
31
|
-
return defaultedOptions;
|
|
32
|
-
}), [queries, client, isRestoring]);
|
|
33
|
-
defaultedQueries.forEach(query => {
|
|
34
|
-
ensureStaleTime(query);
|
|
35
|
-
ensurePreventErrorBoundaryRetry(query, errorResetBoundary);
|
|
36
|
-
});
|
|
37
|
-
useClearResetErrorBoundary(errorResetBoundary);
|
|
38
|
-
const [observer] = React.useState(() => new QueriesObserver(client, defaultedQueries, options));
|
|
39
|
-
const [optimisticResult, getCombinedResult, trackResult] = observer.getOptimisticResult(defaultedQueries);
|
|
40
|
-
React.useSyncExternalStore(React.useCallback(onStoreChange => isRestoring ? () => undefined : observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
41
|
-
React.useEffect(() => {
|
|
42
|
-
// Do not notify on updates because of changes in the options because
|
|
43
|
-
// these changes should already be reflected in the optimistic result.
|
|
44
|
-
observer.setQueries(defaultedQueries, options, {
|
|
45
|
-
listeners: false
|
|
46
|
-
});
|
|
47
|
-
}, [defaultedQueries, options, observer]);
|
|
48
|
-
const shouldAtLeastOneSuspend = optimisticResult.some((result, index) => shouldSuspend(defaultedQueries[index], result, isRestoring));
|
|
49
|
-
const suspensePromises = shouldAtLeastOneSuspend ? optimisticResult.flatMap((result, index) => {
|
|
50
|
-
const opts = defaultedQueries[index];
|
|
51
|
-
const queryObserver = observer.getObservers()[index];
|
|
52
|
-
if (opts && queryObserver) {
|
|
53
|
-
if (shouldSuspend(opts, result, isRestoring)) {
|
|
54
|
-
return fetchOptimistic(opts, queryObserver, errorResetBoundary);
|
|
55
|
-
} else if (willFetch(result, isRestoring)) {
|
|
56
|
-
void fetchOptimistic(opts, queryObserver, errorResetBoundary);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return [];
|
|
60
|
-
}) : [];
|
|
61
|
-
if (suspensePromises.length > 0) {
|
|
62
|
-
throw Promise.all(suspensePromises);
|
|
63
|
-
}
|
|
64
|
-
const observerQueries = observer.getQueries();
|
|
65
|
-
const firstSingleResultWhichShouldThrow = optimisticResult.find((result, index) => getHasError({
|
|
66
|
-
result,
|
|
67
|
-
errorResetBoundary,
|
|
68
|
-
throwOnError: defaultedQueries[index]?.throwOnError ?? false,
|
|
69
|
-
query: observerQueries[index]
|
|
70
|
-
}));
|
|
71
|
-
if (firstSingleResultWhichShouldThrow?.error) {
|
|
72
|
-
throw firstSingleResultWhichShouldThrow.error;
|
|
73
|
-
}
|
|
74
|
-
return getCombinedResult(trackResult());
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export { useQueries };
|
|
78
|
-
//# sourceMappingURL=useQueries.mjs.map
|
package/build/lib/useQuery.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { QueryObserver } from '@tanstack/query-core';
|
|
3
|
-
import { useBaseQuery } from './useBaseQuery.mjs';
|
|
4
|
-
|
|
5
|
-
function queryOptions(options) {
|
|
6
|
-
return options;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// HOOK
|
|
10
|
-
|
|
11
|
-
function useQuery(options, queryClient) {
|
|
12
|
-
return useBaseQuery(options, QueryObserver, queryClient);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { queryOptions, useQuery };
|
|
16
|
-
//# sourceMappingURL=useQuery.mjs.map
|