@depup/reduxjs__toolkit 2.12.0-depup.28 → 2.13.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/changes.json +3 -3
- package/dist/cjs/redux-toolkit.development.cjs +1755 -2247
- package/dist/cjs/redux-toolkit.development.cjs.map +1 -1
- package/dist/cjs/redux-toolkit.production.min.cjs +1 -2
- package/dist/cjs/redux-toolkit.production.min.cjs.map +1 -1
- package/dist/index.d.mts +1496 -1525
- package/dist/index.d.ts +1496 -1525
- package/dist/query/cjs/rtk-query.development.cjs +2059 -2990
- package/dist/query/cjs/rtk-query.development.cjs.map +1 -1
- package/dist/query/cjs/rtk-query.production.min.cjs +1 -1
- package/dist/query/cjs/rtk-query.production.min.cjs.map +1 -1
- package/dist/query/index.d.mts +2300 -2308
- package/dist/query/index.d.ts +2300 -2308
- package/dist/query/react/cjs/rtk-query-react.development.cjs +609 -714
- package/dist/query/react/cjs/rtk-query-react.development.cjs.map +1 -1
- package/dist/query/react/cjs/rtk-query-react.production.min.cjs +1 -1
- package/dist/query/react/cjs/rtk-query-react.production.min.cjs.map +1 -1
- package/dist/query/react/index.d.mts +516 -523
- package/dist/query/react/index.d.ts +516 -523
- package/dist/query/react/rtk-query-react.browser.mjs +1 -1
- package/dist/query/react/rtk-query-react.browser.mjs.map +1 -1
- package/dist/query/react/rtk-query-react.legacy-esm.js +672 -714
- package/dist/query/react/rtk-query-react.legacy-esm.js.map +1 -1
- package/dist/query/react/rtk-query-react.modern.mjs +586 -679
- package/dist/query/react/rtk-query-react.modern.mjs.map +1 -1
- package/dist/query/rtk-query.browser.mjs +1 -1
- package/dist/query/rtk-query.browser.mjs.map +1 -1
- package/dist/query/rtk-query.legacy-esm.js +2175 -3014
- package/dist/query/rtk-query.legacy-esm.js.map +1 -1
- package/dist/query/rtk-query.modern.mjs +2052 -2949
- package/dist/query/rtk-query.modern.mjs.map +1 -1
- package/dist/react/cjs/redux-toolkit-react.development.cjs +30 -51
- package/dist/react/cjs/redux-toolkit-react.development.cjs.map +1 -1
- package/dist/react/cjs/redux-toolkit-react.production.min.cjs +1 -1
- package/dist/react/cjs/redux-toolkit-react.production.min.cjs.map +1 -1
- package/dist/react/index.d.mts +12 -15
- package/dist/react/index.d.ts +12 -15
- package/dist/react/redux-toolkit-react.browser.mjs +1 -1
- package/dist/react/redux-toolkit-react.browser.mjs.map +1 -1
- package/dist/react/redux-toolkit-react.legacy-esm.js +83 -44
- package/dist/react/redux-toolkit-react.legacy-esm.js.map +1 -1
- package/dist/react/redux-toolkit-react.modern.mjs +23 -25
- package/dist/react/redux-toolkit-react.modern.mjs.map +1 -1
- package/dist/redux-toolkit.browser.mjs +1 -2
- package/dist/redux-toolkit.browser.mjs.map +1 -1
- package/dist/redux-toolkit.legacy-esm.js +1748 -2201
- package/dist/redux-toolkit.legacy-esm.js.map +1 -1
- package/dist/redux-toolkit.modern.mjs +1670 -2171
- package/dist/redux-toolkit.modern.mjs.map +1 -1
- package/package.json +17 -33
- package/skills/build-modern-redux-apps/modern-redux/SKILL.md +23 -14
- package/skills/build-modern-redux-apps/modern-redux/references/store-lifetime.md +6 -6
- package/skills/build-modern-redux-apps/redux-dataflow/SKILL.md +13 -10
- package/skills/evolve-and-diagnose-redux-apps/debug-redux-toolkit-apps/SKILL.md +6 -6
- package/skills/evolve-and-diagnose-redux-apps/migrate-to-modern-redux/SKILL.md +7 -8
- package/skills/manage-server-data/adopt-rtk-query/SKILL.md +13 -11
- package/skills/model-redux-state/build-slices-and-selectors/SKILL.md +26 -14
- package/skills/model-redux-state/design-state-ownership/SKILL.md +11 -12
- package/skills/model-redux-state/design-state-ownership/references/state-ownership.md +6 -6
- package/skills/orchestrate-side-effects/handle-side-effects/SKILL.md +27 -23
- package/skills/orchestrate-side-effects/handle-side-effects/references/listener-workflows.md +4 -4
- package/src/autoBatchEnhancer.ts +5 -3
- package/src/combineSlices.ts +5 -5
- package/src/createAction.ts +11 -6
- package/src/createAsyncThunk.ts +14 -2
- package/src/createReducer.ts +1 -1
- package/src/createSlice.ts +9 -4
- package/src/dynamicMiddleware/index.ts +21 -5
- package/src/entities/models.ts +2 -1
- package/src/entities/sorted_state_adapter.ts +35 -24
- package/src/entities/unsorted_state_adapter.ts +1 -1
- package/src/immutableStateInvariantMiddleware.ts +34 -5
- package/src/listenerMiddleware/types.ts +10 -10
- package/src/mapBuilders.ts +2 -5
- package/src/matchers.ts +7 -1
- package/src/query/core/apiState.ts +1 -1
- package/src/query/core/buildInitiate.ts +19 -15
- package/src/query/core/buildMiddleware/cacheLifecycle.ts +3 -1
- package/src/query/core/buildMiddleware/index.ts +1 -1
- package/src/query/core/buildMiddleware/invalidationByTags.ts +4 -1
- package/src/query/core/buildMiddleware/polling.ts +12 -3
- package/src/query/core/buildMiddleware/types.ts +5 -2
- package/src/query/core/buildSlice.ts +2 -2
- package/src/query/core/buildThunks.ts +19 -0
- package/src/query/core/module.ts +9 -3
- package/src/query/createApi.ts +4 -1
- package/src/query/endpointDefinitions.ts +15 -9
- package/src/query/fetchBaseQuery.ts +1 -1
- package/src/query/react/buildHooks.ts +54 -51
- package/src/query/react/namedHooks.ts +28 -24
- package/src/query/utils/isAbsoluteUrl.ts +8 -3
- package/src/serializableStateInvariantMiddleware.ts +1 -1
|
@@ -1,35 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
1
|
+
import { Api, BaseQueryFn, DefinitionType, EndpointDefinitions, InfiniteQueryActionCreatorResult, InfiniteQueryArgFrom, InfiniteQueryDefinition, InfiniteQuerySubState, Module, MutationActionCreatorResult, MutationDefinition, MutationResultSelectorResult, PageParamFrom, PrefetchOptions, QueryActionCreatorResult, QueryArgFrom, QueryDefinition, QueryKeys, QueryStatus, QuerySubState, ResultTypeFrom, SkipToken, SubscriptionOptions, TSHelpersId, TSHelpersOverride, setupListeners } from "@reduxjs/toolkit/query";
|
|
2
|
+
import { CreateSelectorFunction } from "reselect";
|
|
3
|
+
import "@reduxjs/toolkit";
|
|
4
|
+
import "@standard-schema/spec";
|
|
5
|
+
import "redux";
|
|
6
|
+
import "immer";
|
|
7
|
+
import "@standard-schema/utils";
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import { Context } from "react";
|
|
10
|
+
import { ReactReduxContextValue } from "react-redux";
|
|
11
|
+
export * from "@reduxjs/toolkit/query";
|
|
12
|
+
//#region src/query/core/apiState.d.ts
|
|
10
13
|
type InfiniteData<DataType, PageParam> = {
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
pages: Array<DataType>;
|
|
15
|
+
pageParams: Array<PageParam>;
|
|
13
16
|
};
|
|
14
17
|
type InfiniteQueryDirection = 'forward' | 'backward';
|
|
15
|
-
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/query/react/constants.d.ts
|
|
16
20
|
export declare const UNINITIALIZED_VALUE: unique symbol;
|
|
17
21
|
type UninitializedValue = typeof UNINITIALIZED_VALUE;
|
|
18
|
-
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/query/react/buildHooks.d.ts
|
|
19
24
|
type QueryHooks<Definition extends QueryDefinition<any, any, any, any, any>> = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
useQuery: UseQuery<Definition>;
|
|
26
|
+
useLazyQuery: UseLazyQuery<Definition>;
|
|
27
|
+
useQuerySubscription: UseQuerySubscription<Definition>;
|
|
28
|
+
useLazyQuerySubscription: UseLazyQuerySubscription<Definition>;
|
|
29
|
+
useQueryState: UseQueryState<Definition>;
|
|
25
30
|
};
|
|
26
31
|
type InfiniteQueryHooks<Definition extends InfiniteQueryDefinition<any, any, any, any, any>> = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
useInfiniteQuery: UseInfiniteQuery<Definition>;
|
|
33
|
+
useInfiniteQuerySubscription: UseInfiniteQuerySubscription<Definition>;
|
|
34
|
+
useInfiniteQueryState: UseInfiniteQueryState<Definition>;
|
|
30
35
|
};
|
|
31
36
|
type MutationHooks<Definition extends MutationDefinition<any, any, any, any, any>> = {
|
|
32
|
-
|
|
37
|
+
useMutation: UseMutation<Definition>;
|
|
33
38
|
};
|
|
34
39
|
/**
|
|
35
40
|
* A React hook that automatically triggers fetches of data from an endpoint, 'subscribes' the component to the cached data, and reads the request status and cached data from the Redux store. The component will re-render as the loading status changes and the data becomes available.
|
|
@@ -55,48 +60,48 @@ type UseQueryHookResult<D extends QueryDefinition<any, any, any, any>, R = UseQu
|
|
|
55
60
|
*/
|
|
56
61
|
type TypedUseQueryHookResult<ResultType, QueryArg, BaseQuery extends BaseQueryFn, R = UseQueryStateDefaultResult<QueryDefinition<QueryArg, BaseQuery, string, ResultType, string>>> = TypedUseQueryStateResult<ResultType, QueryArg, BaseQuery, R> & TypedUseQuerySubscriptionResult<ResultType, QueryArg, BaseQuery>;
|
|
57
62
|
type UseQuerySubscriptionOptions = SubscriptionOptions & {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Prevents a query from automatically running.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* When `skip` is true (or `skipToken` is passed in as `arg`):
|
|
68
|
+
*
|
|
69
|
+
* - **If the query has cached data:**
|
|
70
|
+
* * The cached data **will not be used** on the initial load, and will ignore updates from any identical query until the `skip` condition is removed
|
|
71
|
+
* * The query will have a status of `uninitialized`
|
|
72
|
+
* * If `skip: false` is set after the initial load, the cached result will be used
|
|
73
|
+
* - **If the query does not have cached data:**
|
|
74
|
+
* * The query will have a status of `uninitialized`
|
|
75
|
+
* * The query will not exist in the state when viewed with the dev tools
|
|
76
|
+
* * The query will not automatically fetch on mount
|
|
77
|
+
* * The query will not automatically run when additional components with the same query are added that do run
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```tsx
|
|
81
|
+
* // codeblock-meta no-transpile title="Skip example"
|
|
82
|
+
* const Pokemon = ({ name, skip }: { name: string; skip: boolean }) => {
|
|
83
|
+
* const { data, error, status } = useGetPokemonByNameQuery(name, {
|
|
84
|
+
* skip,
|
|
85
|
+
* });
|
|
86
|
+
*
|
|
87
|
+
* return (
|
|
88
|
+
* <div>
|
|
89
|
+
* {name} - {status}
|
|
90
|
+
* </div>
|
|
91
|
+
* );
|
|
92
|
+
* };
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
skip?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Defaults to `false`. This setting allows you to control whether if a cached result is already available, RTK Query will only serve a cached result, or if it should `refetch` when set to `true` or if an adequate amount of time has passed since the last successful query result.
|
|
98
|
+
* - `false` - Will not cause a query to be performed _unless_ it does not exist yet.
|
|
99
|
+
* - `true` - Will always refetch when a new subscriber to a query is added. Behaves the same as calling the `refetch` callback or passing `forceRefetch: true` in the action creator.
|
|
100
|
+
* - `number` - **Value is in seconds**. If a number is provided and there is an existing query in the cache, it will compare the current time vs the last fulfilled timestamp, and only refetch if enough time has elapsed.
|
|
101
|
+
*
|
|
102
|
+
* If you specify this option alongside `skip: true`, this **will not be evaluated** until `skip` is false.
|
|
103
|
+
*/
|
|
104
|
+
refetchOnMountOrArgChange?: boolean | number;
|
|
100
105
|
};
|
|
101
106
|
/**
|
|
102
107
|
* Provides a way to reference the options accepted by the `useQuerySubscription`
|
|
@@ -132,7 +137,7 @@ type UseQuerySubscriptionResult<D extends QueryDefinition<any, any, any, any>> =
|
|
|
132
137
|
*/
|
|
133
138
|
type TypedUseQuerySubscriptionResult<ResultType, QueryArg, BaseQuery extends BaseQueryFn> = UseQuerySubscriptionResult<QueryDefinition<QueryArg, BaseQuery, string, ResultType, string>>;
|
|
134
139
|
type UseLazyQueryLastPromiseInfo<D extends QueryDefinition<any, any, any, any>> = {
|
|
135
|
-
|
|
140
|
+
lastArg: QueryArgFrom<D>;
|
|
136
141
|
};
|
|
137
142
|
/**
|
|
138
143
|
* A React hook similar to [`useQuery`](#usequery), but with manual control over when the data fetching occurs.
|
|
@@ -151,18 +156,14 @@ type UseLazyQueryLastPromiseInfo<D extends QueryDefinition<any, any, any, any>>
|
|
|
151
156
|
*
|
|
152
157
|
* When the trigger function returned from a LazyQuery is called, it always initiates a new request to the server even if there is cached data. Set `preferCacheValue`(the second argument to the function) as `true` if you want it to immediately return a cached value if one exists.
|
|
153
158
|
*/
|
|
154
|
-
type UseLazyQuery<D extends QueryDefinition<any, any, any, any>> = <R extends Record<string, any> = UseQueryStateDefaultResult<D>>(options?: SubscriptionOptions & Omit<UseQueryStateOptions<D, R>, 'skip'>) => [
|
|
155
|
-
LazyQueryTrigger<D>,
|
|
156
|
-
UseLazyQueryStateResult<D, R>,
|
|
157
|
-
UseLazyQueryLastPromiseInfo<D>
|
|
158
|
-
];
|
|
159
|
+
type UseLazyQuery<D extends QueryDefinition<any, any, any, any>> = <R extends Record<string, any> = UseQueryStateDefaultResult<D>>(options?: SubscriptionOptions & Omit<UseQueryStateOptions<D, R>, 'skip'>) => [LazyQueryTrigger<D>, UseLazyQueryStateResult<D, R>, UseLazyQueryLastPromiseInfo<D>];
|
|
159
160
|
type TypedUseLazyQuery<ResultType, QueryArg, BaseQuery extends BaseQueryFn> = UseLazyQuery<QueryDefinition<QueryArg, BaseQuery, string, ResultType, string>>;
|
|
160
161
|
type UseLazyQueryStateResult<D extends QueryDefinition<any, any, any, any>, R = UseQueryStateDefaultResult<D>> = UseQueryStateResult<D, R> & {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Resets the hook state to its initial `uninitialized` state.
|
|
164
|
+
* This will also remove the last result from the cache.
|
|
165
|
+
*/
|
|
166
|
+
reset: () => void;
|
|
166
167
|
};
|
|
167
168
|
/**
|
|
168
169
|
* Helper type to manually type the result
|
|
@@ -170,27 +171,27 @@ type UseLazyQueryStateResult<D extends QueryDefinition<any, any, any, any>, R =
|
|
|
170
171
|
*/
|
|
171
172
|
type TypedUseLazyQueryStateResult<ResultType, QueryArg, BaseQuery extends BaseQueryFn, R = UseQueryStateDefaultResult<QueryDefinition<QueryArg, BaseQuery, string, ResultType, string>>> = UseLazyQueryStateResult<QueryDefinition<QueryArg, BaseQuery, string, ResultType, string>, R>;
|
|
172
173
|
type LazyQueryTrigger<D extends QueryDefinition<any, any, any, any>> = {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Triggers a lazy query.
|
|
176
|
+
*
|
|
177
|
+
* By default, this will start a new request even if there is already a value in the cache.
|
|
178
|
+
* If you want to use the cache value and only start a request if there is no cache value, set the second argument to `true`.
|
|
179
|
+
*
|
|
180
|
+
* @remarks
|
|
181
|
+
* If you need to access the error or success payload immediately after a lazy query, you can chain .unwrap().
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* // codeblock-meta title="Using .unwrap with async await"
|
|
186
|
+
* try {
|
|
187
|
+
* const payload = await getUserById(1).unwrap();
|
|
188
|
+
* console.log('fulfilled', payload);
|
|
189
|
+
* } catch (error) {
|
|
190
|
+
* console.error('rejected', error);
|
|
191
|
+
* }
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
(arg: QueryArgFrom<D>, preferCacheValue?: boolean): QueryActionCreatorResult<D>;
|
|
194
195
|
};
|
|
195
196
|
type TypedLazyQueryTrigger<ResultType, QueryArg, BaseQuery extends BaseQueryFn> = LazyQueryTrigger<QueryDefinition<QueryArg, BaseQuery, string, ResultType, string>>;
|
|
196
197
|
/**
|
|
@@ -204,13 +205,9 @@ type TypedLazyQueryTrigger<ResultType, QueryArg, BaseQuery extends BaseQueryFn>
|
|
|
204
205
|
* - 'Subscribes' the component to keep cached data in the store, and 'unsubscribes' when the component unmounts
|
|
205
206
|
* - Accepts polling/re-fetching options to trigger automatic re-fetches when the corresponding criteria is met and the fetch has been manually called at least once
|
|
206
207
|
*/
|
|
207
|
-
type UseLazyQuerySubscription<D extends QueryDefinition<any, any, any, any>> = (options?: SubscriptionOptions) => readonly [
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
{
|
|
211
|
-
reset: () => void;
|
|
212
|
-
}
|
|
213
|
-
];
|
|
208
|
+
type UseLazyQuerySubscription<D extends QueryDefinition<any, any, any, any>> = (options?: SubscriptionOptions) => readonly [LazyQueryTrigger<D>, QueryArgFrom<D> | UninitializedValue, {
|
|
209
|
+
reset: () => void;
|
|
210
|
+
}];
|
|
214
211
|
type TypedUseLazyQuerySubscription<ResultType, QueryArg, BaseQuery extends BaseQueryFn> = UseLazyQuerySubscription<QueryDefinition<QueryArg, BaseQuery, string, ResultType, string>>;
|
|
215
212
|
/**
|
|
216
213
|
* @internal
|
|
@@ -322,72 +319,72 @@ type TypedUseQueryState<ResultType, QueryArg, BaseQuery extends BaseQueryFn> = U
|
|
|
322
319
|
* @internal
|
|
323
320
|
*/
|
|
324
321
|
type UseQueryStateOptions<D extends QueryDefinition<any, any, any, any>, R extends Record<string, any>> = {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
322
|
+
/**
|
|
323
|
+
* Prevents a query from automatically running.
|
|
324
|
+
*
|
|
325
|
+
* @remarks
|
|
326
|
+
* When skip is true:
|
|
327
|
+
*
|
|
328
|
+
* - **If the query has cached data:**
|
|
329
|
+
* * The cached data **will not be used** on the initial load, and will ignore updates from any identical query until the `skip` condition is removed
|
|
330
|
+
* * The query will have a status of `uninitialized`
|
|
331
|
+
* * If `skip: false` is set after skipping the initial load, the cached result will be used
|
|
332
|
+
* - **If the query does not have cached data:**
|
|
333
|
+
* * The query will have a status of `uninitialized`
|
|
334
|
+
* * The query will not exist in the state when viewed with the dev tools
|
|
335
|
+
* * The query will not automatically fetch on mount
|
|
336
|
+
* * The query will not automatically run when additional components with the same query are added that do run
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```tsx
|
|
340
|
+
* // codeblock-meta title="Skip example"
|
|
341
|
+
* const Pokemon = ({ name, skip }: { name: string; skip: boolean }) => {
|
|
342
|
+
* const { data, error, status } = useGetPokemonByNameQuery(name, {
|
|
343
|
+
* skip,
|
|
344
|
+
* });
|
|
345
|
+
*
|
|
346
|
+
* return (
|
|
347
|
+
* <div>
|
|
348
|
+
* {name} - {status}
|
|
349
|
+
* </div>
|
|
350
|
+
* );
|
|
351
|
+
* };
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
skip?: boolean;
|
|
355
|
+
/**
|
|
356
|
+
* `selectFromResult` allows you to get a specific segment from a query result in a performant manner.
|
|
357
|
+
* When using this feature, the component will not rerender unless the underlying data of the selected item has changed.
|
|
358
|
+
* If the selected item is one element in a larger collection, it will disregard changes to elements in the same collection.
|
|
359
|
+
*
|
|
360
|
+
* @example
|
|
361
|
+
* ```tsx
|
|
362
|
+
* // codeblock-meta title="Using selectFromResult to extract a single result"
|
|
363
|
+
* function PostsList() {
|
|
364
|
+
* const { data: posts } = api.useGetPostsQuery();
|
|
365
|
+
*
|
|
366
|
+
* return (
|
|
367
|
+
* <ul>
|
|
368
|
+
* {posts?.map((post) => (
|
|
369
|
+
* <PostById key={post.id} id={post.id} />
|
|
370
|
+
* ))}
|
|
371
|
+
* </ul>
|
|
372
|
+
* );
|
|
373
|
+
* }
|
|
374
|
+
*
|
|
375
|
+
* function PostById({ id }: { id: number }) {
|
|
376
|
+
* // Will select the post with the given id, and will only rerender if the given posts data changes
|
|
377
|
+
* const { post } = api.useGetPostsQuery(undefined, {
|
|
378
|
+
* selectFromResult: ({ data }) => ({
|
|
379
|
+
* post: data?.find((post) => post.id === id),
|
|
380
|
+
* }),
|
|
381
|
+
* });
|
|
382
|
+
*
|
|
383
|
+
* return <li>{post?.name}</li>;
|
|
384
|
+
* }
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
selectFromResult?: QueryStateSelector<R, D>;
|
|
391
388
|
};
|
|
392
389
|
/**
|
|
393
390
|
* Provides a way to define a "pre-typed" version of
|
|
@@ -458,154 +455,154 @@ type UseQueryStateResult<_ extends QueryDefinition<any, any, any, any>, R> = R;
|
|
|
458
455
|
*/
|
|
459
456
|
type TypedUseQueryStateResult<ResultType, QueryArg, BaseQuery extends BaseQueryFn, R = UseQueryStateDefaultResult<QueryDefinition<QueryArg, BaseQuery, string, ResultType, string>>> = R;
|
|
460
457
|
type UseQueryStateBaseResult<D extends QueryDefinition<any, any, any, any>> = QuerySubState<D> & {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
458
|
+
/**
|
|
459
|
+
* Where `data` tries to hold data as much as possible, also reusing
|
|
460
|
+
* data from the last arguments passed into the hook, this property
|
|
461
|
+
* will always contain the received data from the query, for the current query arguments.
|
|
462
|
+
*/
|
|
463
|
+
currentData?: ResultTypeFrom<D>;
|
|
464
|
+
/**
|
|
465
|
+
* Query has not started yet.
|
|
466
|
+
*/
|
|
467
|
+
isUninitialized: false;
|
|
468
|
+
/**
|
|
469
|
+
* Query is currently loading for the first time. No data yet.
|
|
470
|
+
*/
|
|
471
|
+
isLoading: false;
|
|
472
|
+
/**
|
|
473
|
+
* Query is currently fetching, but might have data from an earlier request.
|
|
474
|
+
*/
|
|
475
|
+
isFetching: false;
|
|
476
|
+
/**
|
|
477
|
+
* Query has data from a successful load.
|
|
478
|
+
*/
|
|
479
|
+
isSuccess: false;
|
|
480
|
+
/**
|
|
481
|
+
* Query is currently in "error" state.
|
|
482
|
+
*/
|
|
483
|
+
isError: false;
|
|
487
484
|
};
|
|
488
485
|
type UseQueryStateUninitialized<D extends QueryDefinition<any, any, any, any>> = TSHelpersOverride<Extract<UseQueryStateBaseResult<D>, {
|
|
489
|
-
|
|
486
|
+
status: QueryStatus.uninitialized;
|
|
490
487
|
}>, {
|
|
491
|
-
|
|
488
|
+
isUninitialized: true;
|
|
492
489
|
}>;
|
|
493
490
|
type UseQueryStateLoading<D extends QueryDefinition<any, any, any, any>> = TSHelpersOverride<UseQueryStateBaseResult<D>, {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
491
|
+
isLoading: true;
|
|
492
|
+
isFetching: boolean;
|
|
493
|
+
data: undefined;
|
|
497
494
|
}>;
|
|
498
495
|
type UseQueryStateSuccessFetching<D extends QueryDefinition<any, any, any, any>> = TSHelpersOverride<UseQueryStateBaseResult<D>, {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
496
|
+
isSuccess: true;
|
|
497
|
+
isFetching: true;
|
|
498
|
+
error: undefined;
|
|
502
499
|
} & {
|
|
503
|
-
|
|
500
|
+
data: ResultTypeFrom<D>;
|
|
504
501
|
} & Required<Pick<UseQueryStateBaseResult<D>, 'fulfilledTimeStamp'>>>;
|
|
505
502
|
type UseQueryStateSuccessNotFetching<D extends QueryDefinition<any, any, any, any>> = TSHelpersOverride<UseQueryStateBaseResult<D>, {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
503
|
+
isSuccess: true;
|
|
504
|
+
isFetching: false;
|
|
505
|
+
error: undefined;
|
|
509
506
|
} & {
|
|
510
|
-
|
|
511
|
-
|
|
507
|
+
data: ResultTypeFrom<D>;
|
|
508
|
+
currentData: ResultTypeFrom<D>;
|
|
512
509
|
} & Required<Pick<UseQueryStateBaseResult<D>, 'fulfilledTimeStamp'>>>;
|
|
513
510
|
type UseQueryStateError<D extends QueryDefinition<any, any, any, any>> = TSHelpersOverride<UseQueryStateBaseResult<D>, {
|
|
514
|
-
|
|
511
|
+
isError: true;
|
|
515
512
|
} & Required<Pick<UseQueryStateBaseResult<D>, 'error'>>>;
|
|
516
513
|
type UseQueryStateDefaultResult<D extends QueryDefinition<any, any, any, any>> = TSHelpersId<UseQueryStateUninitialized<D> | UseQueryStateLoading<D> | UseQueryStateSuccessFetching<D> | UseQueryStateSuccessNotFetching<D> | UseQueryStateError<D>> & {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
514
|
+
/**
|
|
515
|
+
* @deprecated Included for completeness, but discouraged.
|
|
516
|
+
* Please use the `isLoading`, `isFetching`, `isSuccess`, `isError`
|
|
517
|
+
* and `isUninitialized` flags instead
|
|
518
|
+
*/
|
|
519
|
+
status: QueryStatus;
|
|
523
520
|
};
|
|
524
521
|
type LazyInfiniteQueryTrigger<D extends InfiniteQueryDefinition<any, any, any, any, any>> = {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
522
|
+
/**
|
|
523
|
+
* Triggers a lazy query.
|
|
524
|
+
*
|
|
525
|
+
* By default, this will start a new request even if there is already a value in the cache.
|
|
526
|
+
* If you want to use the cache value and only start a request if there is no cache value, set the second argument to `true`.
|
|
527
|
+
*
|
|
528
|
+
* @remarks
|
|
529
|
+
* If you need to access the error or success payload immediately after a lazy query, you can chain .unwrap().
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* ```ts
|
|
533
|
+
* // codeblock-meta title="Using .unwrap with async await"
|
|
534
|
+
* try {
|
|
535
|
+
* const payload = await getUserById(1).unwrap();
|
|
536
|
+
* console.log('fulfilled', payload);
|
|
537
|
+
* } catch (error) {
|
|
538
|
+
* console.error('rejected', error);
|
|
539
|
+
* }
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
542
|
+
(arg: QueryArgFrom<D>, direction: InfiniteQueryDirection): InfiniteQueryActionCreatorResult<D>;
|
|
546
543
|
};
|
|
547
544
|
type TypedLazyInfiniteQueryTrigger<ResultType, QueryArg, PageParam, BaseQuery extends BaseQueryFn> = LazyInfiniteQueryTrigger<InfiniteQueryDefinition<QueryArg, PageParam, BaseQuery, string, ResultType, string>>;
|
|
548
545
|
type UseInfiniteQuerySubscriptionOptions<D extends InfiniteQueryDefinition<any, any, any, any, any>> = SubscriptionOptions & {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
546
|
+
/**
|
|
547
|
+
* Prevents a query from automatically running.
|
|
548
|
+
*
|
|
549
|
+
* @remarks
|
|
550
|
+
* When `skip` is true (or `skipToken` is passed in as `arg`):
|
|
551
|
+
*
|
|
552
|
+
* - **If the query has cached data:**
|
|
553
|
+
* * The cached data **will not be used** on the initial load, and will ignore updates from any identical query until the `skip` condition is removed
|
|
554
|
+
* * The query will have a status of `uninitialized`
|
|
555
|
+
* * If `skip: false` is set after the initial load, the cached result will be used
|
|
556
|
+
* - **If the query does not have cached data:**
|
|
557
|
+
* * The query will have a status of `uninitialized`
|
|
558
|
+
* * The query will not exist in the state when viewed with the dev tools
|
|
559
|
+
* * The query will not automatically fetch on mount
|
|
560
|
+
* * The query will not automatically run when additional components with the same query are added that do run
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* ```tsx
|
|
564
|
+
* // codeblock-meta no-transpile title="Skip example"
|
|
565
|
+
* const Pokemon = ({ name, skip }: { name: string; skip: boolean }) => {
|
|
566
|
+
* const { data, error, status } = useGetPokemonByNameQuery(name, {
|
|
567
|
+
* skip,
|
|
568
|
+
* });
|
|
569
|
+
*
|
|
570
|
+
* return (
|
|
571
|
+
* <div>
|
|
572
|
+
* {name} - {status}
|
|
573
|
+
* </div>
|
|
574
|
+
* );
|
|
575
|
+
* };
|
|
576
|
+
* ```
|
|
577
|
+
*/
|
|
578
|
+
skip?: boolean;
|
|
579
|
+
/**
|
|
580
|
+
* Defaults to `false`. This setting allows you to control whether if a cached result is already available, RTK Query will only serve a cached result, or if it should `refetch` when set to `true` or if an adequate amount of time has passed since the last successful query result.
|
|
581
|
+
* - `false` - Will not cause a query to be performed _unless_ it does not exist yet.
|
|
582
|
+
* - `true` - Will always refetch when a new subscriber to a query is added. Behaves the same as calling the `refetch` callback or passing `forceRefetch: true` in the action creator.
|
|
583
|
+
* - `number` - **Value is in seconds**. If a number is provided and there is an existing query in the cache, it will compare the current time vs the last fulfilled timestamp, and only refetch if enough time has elapsed.
|
|
584
|
+
*
|
|
585
|
+
* If you specify this option alongside `skip: true`, this **will not be evaluated** until `skip` is false.
|
|
586
|
+
*/
|
|
587
|
+
refetchOnMountOrArgChange?: boolean | number;
|
|
588
|
+
initialPageParam?: PageParamFrom<D>;
|
|
589
|
+
/**
|
|
590
|
+
* Defaults to `true`. When this is `true` and an infinite query endpoint is refetched
|
|
591
|
+
* (due to tag invalidation, polling, arg change configuration, or manual refetching),
|
|
592
|
+
* RTK Query will try to sequentially refetch all pages currently in the cache.
|
|
593
|
+
* When `false` only the first page will be refetched.
|
|
594
|
+
*
|
|
595
|
+
* This option applies to all automatic refetches for this subscription (polling, tag invalidation, etc.).
|
|
596
|
+
* It can be overridden on a per-call basis using the `refetch()` method.
|
|
597
|
+
*/
|
|
598
|
+
refetchCachedPages?: boolean;
|
|
602
599
|
};
|
|
603
600
|
type TypedUseInfiniteQuerySubscription<ResultType, QueryArg, PageParam, BaseQuery extends BaseQueryFn> = UseInfiniteQuerySubscription<InfiniteQueryDefinition<QueryArg, PageParam, BaseQuery, string, ResultType, string>>;
|
|
604
601
|
type UseInfiniteQuerySubscriptionResult<D extends InfiniteQueryDefinition<any, any, any, any, any>> = {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
602
|
+
refetch: (options?: Pick<UseInfiniteQuerySubscriptionOptions<D>, 'refetchCachedPages'>) => InfiniteQueryActionCreatorResult<D>;
|
|
603
|
+
trigger: LazyInfiniteQueryTrigger<D>;
|
|
604
|
+
fetchNextPage: () => InfiniteQueryActionCreatorResult<D>;
|
|
605
|
+
fetchPreviousPage: () => InfiniteQueryActionCreatorResult<D>;
|
|
609
606
|
};
|
|
610
607
|
/**
|
|
611
608
|
* Helper type to manually type the result
|
|
@@ -671,139 +668,141 @@ type UseInfiniteQuerySubscription<D extends InfiniteQueryDefinition<any, any, an
|
|
|
671
668
|
type UseInfiniteQueryHookResult<D extends InfiniteQueryDefinition<any, any, any, any, any>, R = UseInfiniteQueryStateDefaultResult<D>> = UseInfiniteQueryStateResult<D, R> & Pick<UseInfiniteQuerySubscriptionResult<D>, 'refetch' | 'fetchNextPage' | 'fetchPreviousPage'>;
|
|
672
669
|
type TypedUseInfiniteQueryHookResult<ResultType, QueryArg, PageParam, BaseQuery extends BaseQueryFn, R extends Record<string, any> = UseInfiniteQueryStateDefaultResult<InfiniteQueryDefinition<QueryArg, PageParam, BaseQuery, string, ResultType, string>>> = UseInfiniteQueryHookResult<InfiniteQueryDefinition<QueryArg, PageParam, BaseQuery, string, ResultType, string>, R>;
|
|
673
670
|
type UseInfiniteQueryStateOptions<D extends InfiniteQueryDefinition<any, any, any, any, any>, R extends Record<string, any>> = {
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
671
|
+
/**
|
|
672
|
+
* Prevents a query from automatically running.
|
|
673
|
+
*
|
|
674
|
+
* @remarks
|
|
675
|
+
* When skip is true:
|
|
676
|
+
*
|
|
677
|
+
* - **If the query has cached data:**
|
|
678
|
+
* * The cached data **will not be used** on the initial load, and will ignore updates from any identical query until the `skip` condition is removed
|
|
679
|
+
* * The query will have a status of `uninitialized`
|
|
680
|
+
* * If `skip: false` is set after skipping the initial load, the cached result will be used
|
|
681
|
+
* - **If the query does not have cached data:**
|
|
682
|
+
* * The query will have a status of `uninitialized`
|
|
683
|
+
* * The query will not exist in the state when viewed with the dev tools
|
|
684
|
+
* * The query will not automatically fetch on mount
|
|
685
|
+
* * The query will not automatically run when additional components with the same query are added that do run
|
|
686
|
+
*
|
|
687
|
+
* @example
|
|
688
|
+
* ```tsx
|
|
689
|
+
* // codeblock-meta title="Skip example"
|
|
690
|
+
* const Pokemon = ({ name, skip }: { name: string; skip: boolean }) => {
|
|
691
|
+
* const { data, error, status } = useGetPokemonByNameQuery(name, {
|
|
692
|
+
* skip,
|
|
693
|
+
* });
|
|
694
|
+
*
|
|
695
|
+
* return (
|
|
696
|
+
* <div>
|
|
697
|
+
* {name} - {status}
|
|
698
|
+
* </div>
|
|
699
|
+
* );
|
|
700
|
+
* };
|
|
701
|
+
* ```
|
|
702
|
+
*/
|
|
703
|
+
skip?: boolean;
|
|
704
|
+
/**
|
|
705
|
+
* `selectFromResult` allows you to get a specific segment from a query result in a performant manner.
|
|
706
|
+
* When using this feature, the component will not rerender unless the underlying data of the selected item has changed.
|
|
707
|
+
* If the selected item is one element in a larger collection, it will disregard changes to elements in the same collection.
|
|
708
|
+
* Note that this should always return an object (not a primitive), as RTKQ adds fields to the return value.
|
|
709
|
+
*
|
|
710
|
+
* @example
|
|
711
|
+
* ```tsx
|
|
712
|
+
* // codeblock-meta title="Using selectFromResult to extract a single result"
|
|
713
|
+
* function PostsList() {
|
|
714
|
+
* const { data: posts } = api.useGetPostsQuery();
|
|
715
|
+
*
|
|
716
|
+
* return (
|
|
717
|
+
* <ul>
|
|
718
|
+
* {posts?.map((post) => (
|
|
719
|
+
* <PostById key={post.id} id={post.id} />
|
|
720
|
+
* ))}
|
|
721
|
+
* </ul>
|
|
722
|
+
* );
|
|
723
|
+
* }
|
|
724
|
+
*
|
|
725
|
+
* function PostById({ id }: { id: number }) {
|
|
726
|
+
* // Will select the post with the given id, and will only rerender if the given posts data changes
|
|
727
|
+
* const { post } = api.useGetPostsQuery(undefined, {
|
|
728
|
+
* selectFromResult: ({ data }) => ({
|
|
729
|
+
* post: data?.find((post) => post.id === id),
|
|
730
|
+
* }),
|
|
731
|
+
* });
|
|
732
|
+
*
|
|
733
|
+
* return <li>{post?.name}</li>;
|
|
734
|
+
* }
|
|
735
|
+
* ```
|
|
736
|
+
*/
|
|
737
|
+
selectFromResult?: InfiniteQueryStateSelector<R, D>;
|
|
741
738
|
};
|
|
742
739
|
type TypedUseInfiniteQueryStateOptions<ResultType, QueryArg, PageParam, BaseQuery extends BaseQueryFn, SelectedResult extends Record<string, any> = UseInfiniteQueryStateDefaultResult<InfiniteQueryDefinition<QueryArg, PageParam, BaseQuery, string, ResultType, string>>> = UseInfiniteQueryStateOptions<InfiniteQueryDefinition<QueryArg, PageParam, BaseQuery, string, ResultType, string>, SelectedResult>;
|
|
743
740
|
type UseInfiniteQueryStateResult<D extends InfiniteQueryDefinition<any, any, any, any, any>, R = UseInfiniteQueryStateDefaultResult<D>> = R;
|
|
744
741
|
type TypedUseInfiniteQueryStateResult<ResultType, QueryArg, PageParam, BaseQuery extends BaseQueryFn, R = UseInfiniteQueryStateDefaultResult<InfiniteQueryDefinition<QueryArg, PageParam, BaseQuery, string, ResultType, string>>> = UseInfiniteQueryStateResult<InfiniteQueryDefinition<QueryArg, PageParam, BaseQuery, string, ResultType, string>, R>;
|
|
745
742
|
type UseInfiniteQueryStateBaseResult<D extends InfiniteQueryDefinition<any, any, any, any, any>> = InfiniteQuerySubState<D> & {
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
743
|
+
/**
|
|
744
|
+
* Where `data` tries to hold data as much as possible, also reusing
|
|
745
|
+
* data from the last arguments passed into the hook, this property
|
|
746
|
+
* will always contain the received data from the query, for the current query arguments.
|
|
747
|
+
*/
|
|
748
|
+
currentData?: InfiniteData<ResultTypeFrom<D>, PageParamFrom<D>>;
|
|
749
|
+
/**
|
|
750
|
+
* Query has not started yet.
|
|
751
|
+
*/
|
|
752
|
+
isUninitialized: false;
|
|
753
|
+
/**
|
|
754
|
+
* Query is currently loading for the first time. No data yet.
|
|
755
|
+
*/
|
|
756
|
+
isLoading: false;
|
|
757
|
+
/**
|
|
758
|
+
* Query is currently fetching, but might have data from an earlier request.
|
|
759
|
+
*/
|
|
760
|
+
isFetching: false;
|
|
761
|
+
/**
|
|
762
|
+
* Query has data from a successful load.
|
|
763
|
+
*/
|
|
764
|
+
isSuccess: false;
|
|
765
|
+
/**
|
|
766
|
+
* Query is currently in "error" state.
|
|
767
|
+
*/
|
|
768
|
+
isError: false;
|
|
769
|
+
hasNextPage: boolean;
|
|
770
|
+
hasPreviousPage: boolean;
|
|
771
|
+
isFetchingNextPage: boolean;
|
|
772
|
+
isFetchingPreviousPage: boolean;
|
|
773
|
+
isFetchNextPageError: boolean;
|
|
774
|
+
isFetchPreviousPageError: boolean;
|
|
776
775
|
};
|
|
777
776
|
type UseInfiniteQueryStateDefaultResult<D extends InfiniteQueryDefinition<any, any, any, any, any>> = TSHelpersId<TSHelpersOverride<Extract<UseInfiniteQueryStateBaseResult<D>, {
|
|
778
|
-
|
|
777
|
+
status: QueryStatus.uninitialized;
|
|
779
778
|
}>, {
|
|
780
|
-
|
|
779
|
+
isUninitialized: true;
|
|
781
780
|
}> | TSHelpersOverride<UseInfiniteQueryStateBaseResult<D>, {
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
781
|
+
isLoading: true;
|
|
782
|
+
isFetching: boolean;
|
|
783
|
+
data: undefined;
|
|
785
784
|
} | ({
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
785
|
+
isSuccess: true;
|
|
786
|
+
isFetching: true;
|
|
787
|
+
error: undefined;
|
|
789
788
|
} & Required<Pick<UseInfiniteQueryStateBaseResult<D>, 'data' | 'fulfilledTimeStamp'>>) | ({
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
789
|
+
isSuccess: true;
|
|
790
|
+
isFetching: false;
|
|
791
|
+
error: undefined;
|
|
793
792
|
} & Required<Pick<UseInfiniteQueryStateBaseResult<D>, 'data' | 'fulfilledTimeStamp' | 'currentData'>>) | ({
|
|
794
|
-
|
|
793
|
+
isError: true;
|
|
795
794
|
} & Required<Pick<UseInfiniteQueryStateBaseResult<D>, 'error'>>)>> & {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
795
|
+
/**
|
|
796
|
+
* @deprecated Included for completeness, but discouraged.
|
|
797
|
+
* Please use the `isLoading`, `isFetching`, `isSuccess`, `isError`
|
|
798
|
+
* and `isUninitialized` flags instead
|
|
799
|
+
*/
|
|
800
|
+
status: QueryStatus;
|
|
802
801
|
};
|
|
803
802
|
type MutationStateSelector<R extends Record<string, any>, D extends MutationDefinition<any, any, any, any>> = (state: MutationResultSelectorResult<D>) => R;
|
|
804
803
|
type UseMutationStateOptions<D extends MutationDefinition<any, any, any, any>, R extends Record<string, any>> = {
|
|
805
|
-
|
|
806
|
-
|
|
804
|
+
selectFromResult?: MutationStateSelector<R, D>;
|
|
805
|
+
fixedCacheKey?: string;
|
|
807
806
|
};
|
|
808
807
|
/**
|
|
809
808
|
* Provides a way to define a "pre-typed" version of
|
|
@@ -819,12 +818,12 @@ type UseMutationStateOptions<D extends MutationDefinition<any, any, any, any>, R
|
|
|
819
818
|
*/
|
|
820
819
|
type TypedUseMutationStateOptions<ResultType, QueryArg, BaseQuery extends BaseQueryFn, SelectedResult extends Record<string, any> = MutationResultSelectorResult<MutationDefinition<QueryArg, BaseQuery, string, ResultType, string>>> = UseMutationStateOptions<MutationDefinition<QueryArg, BaseQuery, string, ResultType, string>, SelectedResult>;
|
|
821
820
|
type UseMutationStateResult<D extends MutationDefinition<any, any, any, any>, R> = R & {
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
821
|
+
originalArgs?: QueryArgFrom<D>;
|
|
822
|
+
/**
|
|
823
|
+
* Resets the hook state to its initial `uninitialized` state.
|
|
824
|
+
* This will also remove the last result from the cache.
|
|
825
|
+
*/
|
|
826
|
+
reset: () => void;
|
|
828
827
|
};
|
|
829
828
|
/**
|
|
830
829
|
* Helper type to manually type the result
|
|
@@ -844,112 +843,104 @@ type TypedUseMutationResult<ResultType, QueryArg, BaseQuery extends BaseQueryFn,
|
|
|
844
843
|
type UseMutation<D extends MutationDefinition<any, any, any, any>> = <R extends Record<string, any> = MutationResultSelectorResult<D>>(options?: UseMutationStateOptions<D, R>) => readonly [MutationTrigger<D>, UseMutationStateResult<D, R>];
|
|
845
844
|
type TypedUseMutation<ResultType, QueryArg, BaseQuery extends BaseQueryFn> = UseMutation<MutationDefinition<QueryArg, BaseQuery, string, ResultType, string>>;
|
|
846
845
|
type MutationTrigger<D extends MutationDefinition<any, any, any, any>> = {
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
846
|
+
/**
|
|
847
|
+
* Triggers the mutation and returns a Promise.
|
|
848
|
+
* @remarks
|
|
849
|
+
* If you need to access the error or success payload immediately after a mutation, you can chain .unwrap().
|
|
850
|
+
*
|
|
851
|
+
* @example
|
|
852
|
+
* ```ts
|
|
853
|
+
* // codeblock-meta title="Using .unwrap with async await"
|
|
854
|
+
* try {
|
|
855
|
+
* const payload = await addPost({ id: 1, name: 'Example' }).unwrap();
|
|
856
|
+
* console.log('fulfilled', payload);
|
|
857
|
+
* } catch (error) {
|
|
858
|
+
* console.error('rejected', error);
|
|
859
|
+
* }
|
|
860
|
+
* ```
|
|
861
|
+
*/
|
|
862
|
+
(arg: QueryArgFrom<D>): MutationActionCreatorResult<D>;
|
|
864
863
|
};
|
|
865
864
|
type TypedMutationTrigger<ResultType, QueryArg, BaseQuery extends BaseQueryFn> = MutationTrigger<MutationDefinition<QueryArg, BaseQuery, string, ResultType, string>>;
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
type
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
};
|
|
877
|
-
type
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
} ? `use${Capitalize<K & string>}InfiniteQuery` : never]: UseInfiniteQuery<Extract<Definitions[K], InfiniteQueryDefinition<any, any, any, any, any>>>;
|
|
881
|
-
};
|
|
882
|
-
type MutationHookNames<Definitions extends EndpointDefinitions> = {
|
|
883
|
-
[K in keyof Definitions as Definitions[K] extends {
|
|
884
|
-
type: DefinitionType.mutation;
|
|
885
|
-
} ? `use${Capitalize<K & string>}Mutation` : never]: UseMutation<Extract<Definitions[K], MutationDefinition<any, any, any, any>>>;
|
|
886
|
-
};
|
|
865
|
+
//#endregion
|
|
866
|
+
//#region src/query/react/namedHooks.d.ts
|
|
867
|
+
type QueryHookNames<Definitions extends EndpointDefinitions> = { [K in keyof Definitions as Definitions[K] extends {
|
|
868
|
+
type: DefinitionType.query;
|
|
869
|
+
} ? `use${Capitalize<K & string>}Query` : never]: UseQuery<Extract<Definitions[K], QueryDefinition<any, any, any, any>>>; };
|
|
870
|
+
type LazyQueryHookNames<Definitions extends EndpointDefinitions> = { [K in keyof Definitions as Definitions[K] extends {
|
|
871
|
+
type: DefinitionType.query;
|
|
872
|
+
} ? `useLazy${Capitalize<K & string>}Query` : never]: UseLazyQuery<Extract<Definitions[K], QueryDefinition<any, any, any, any>>>; };
|
|
873
|
+
type InfiniteQueryHookNames<Definitions extends EndpointDefinitions> = { [K in keyof Definitions as Definitions[K] extends {
|
|
874
|
+
type: DefinitionType.infinitequery;
|
|
875
|
+
} ? `use${Capitalize<K & string>}InfiniteQuery` : never]: UseInfiniteQuery<Extract<Definitions[K], InfiniteQueryDefinition<any, any, any, any, any>>>; };
|
|
876
|
+
type MutationHookNames<Definitions extends EndpointDefinitions> = { [K in keyof Definitions as Definitions[K] extends {
|
|
877
|
+
type: DefinitionType.mutation;
|
|
878
|
+
} ? `use${Capitalize<K & string>}Mutation` : never]: UseMutation<Extract<Definitions[K], MutationDefinition<any, any, any, any>>>; };
|
|
887
879
|
type HooksWithUniqueNames<Definitions extends EndpointDefinitions> = QueryHookNames<Definitions> & LazyQueryHookNames<Definitions> & InfiniteQueryHookNames<Definitions> & MutationHookNames<Definitions>;
|
|
888
|
-
|
|
880
|
+
//#endregion
|
|
881
|
+
//#region src/query/react/module.d.ts
|
|
889
882
|
export declare const reactHooksModuleName: unique symbol;
|
|
890
883
|
type ReactHooksModule = typeof reactHooksModuleName;
|
|
891
884
|
declare module '@reduxjs/toolkit/query' {
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
} & HooksWithUniqueNames<Definitions>;
|
|
905
|
-
}
|
|
885
|
+
interface ApiModules<BaseQuery extends BaseQueryFn, Definitions extends EndpointDefinitions, ReducerPath extends string, TagTypes extends string> {
|
|
886
|
+
[reactHooksModuleName]: {
|
|
887
|
+
/**
|
|
888
|
+
* Endpoints based on the input endpoints provided to `createApi`, containing `select`, `hooks` and `action matchers`.
|
|
889
|
+
*/
|
|
890
|
+
endpoints: { [K in keyof Definitions]: Definitions[K] extends QueryDefinition<any, any, any, any, any> ? QueryHooks<Definitions[K]> : Definitions[K] extends MutationDefinition<any, any, any, any, any> ? MutationHooks<Definitions[K]> : Definitions[K] extends InfiniteQueryDefinition<any, any, any, any, any> ? InfiniteQueryHooks<Definitions[K]> : never; };
|
|
891
|
+
/**
|
|
892
|
+
* A hook that accepts a string endpoint name, and provides a callback that when called, pre-fetches the data for that endpoint.
|
|
893
|
+
*/
|
|
894
|
+
usePrefetch<EndpointName extends QueryKeys<Definitions>>(endpointName: EndpointName, options?: PrefetchOptions): (arg: QueryArgFrom<Definitions[EndpointName]>, options?: PrefetchOptions) => void;
|
|
895
|
+
} & HooksWithUniqueNames<Definitions>;
|
|
896
|
+
}
|
|
906
897
|
}
|
|
907
|
-
type RR = typeof
|
|
898
|
+
type RR = typeof import('react-redux');
|
|
908
899
|
interface ReactHooksModuleOptions {
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
900
|
+
/**
|
|
901
|
+
* The hooks from React Redux to be used
|
|
902
|
+
*/
|
|
903
|
+
hooks?: {
|
|
904
|
+
/**
|
|
905
|
+
* The version of the `useDispatch` hook to be used
|
|
906
|
+
*/
|
|
907
|
+
useDispatch: RR['useDispatch'];
|
|
908
|
+
/**
|
|
909
|
+
* The version of the `useSelector` hook to be used
|
|
910
|
+
*/
|
|
911
|
+
useSelector: RR['useSelector'];
|
|
912
|
+
/**
|
|
913
|
+
* The version of the `useStore` hook to be used
|
|
914
|
+
*/
|
|
915
|
+
useStore: RR['useStore'];
|
|
916
|
+
};
|
|
917
|
+
/**
|
|
918
|
+
* The version of the `batchedUpdates` function to be used
|
|
919
|
+
*/
|
|
920
|
+
batch?: RR['batch'];
|
|
921
|
+
/**
|
|
922
|
+
* Enables performing asynchronous tasks immediately within a render.
|
|
923
|
+
*
|
|
924
|
+
* @example
|
|
925
|
+
*
|
|
926
|
+
* ```ts
|
|
927
|
+
* import {
|
|
928
|
+
* buildCreateApi,
|
|
929
|
+
* coreModule,
|
|
930
|
+
* reactHooksModule
|
|
931
|
+
* } from '@reduxjs/toolkit/query/react'
|
|
932
|
+
*
|
|
933
|
+
* const createApi = buildCreateApi(
|
|
934
|
+
* coreModule(),
|
|
935
|
+
* reactHooksModule({ unstable__sideEffectsInRender: true })
|
|
936
|
+
* )
|
|
937
|
+
* ```
|
|
938
|
+
*/
|
|
939
|
+
unstable__sideEffectsInRender?: boolean;
|
|
940
|
+
/**
|
|
941
|
+
* A selector creator (usually from `reselect`, or matching the same signature)
|
|
942
|
+
*/
|
|
943
|
+
createSelector?: CreateSelectorFunction<any, any, any>;
|
|
953
944
|
}
|
|
954
945
|
/**
|
|
955
946
|
* Creates a module that generates react hooks from endpoints, for use with `buildCreateApi`.
|
|
@@ -972,7 +963,8 @@ interface ReactHooksModuleOptions {
|
|
|
972
963
|
* @returns A module for use with `buildCreateApi`
|
|
973
964
|
*/
|
|
974
965
|
declare const reactHooksModule: ({ batch, hooks, createSelector, unstable__sideEffectsInRender, ...rest }?: ReactHooksModuleOptions) => Module<ReactHooksModule>;
|
|
975
|
-
|
|
966
|
+
//#endregion
|
|
967
|
+
//#region src/query/react/ApiProvider.d.ts
|
|
976
968
|
/**
|
|
977
969
|
* Can be used as a `Provider` if you **do not already have a Redux store**.
|
|
978
970
|
*
|
|
@@ -998,12 +990,13 @@ declare const reactHooksModule: ({ batch, hooks, createSelector, unstable__sideE
|
|
|
998
990
|
* in that case.
|
|
999
991
|
*/
|
|
1000
992
|
declare function ApiProvider(props: {
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
993
|
+
children: any;
|
|
994
|
+
api: Api<any, {}, any, any>;
|
|
995
|
+
setupListeners?: Parameters<typeof setupListeners>[1] | false;
|
|
996
|
+
context?: Context<ReactReduxContextValue | null>;
|
|
1005
997
|
}): React.JSX.Element;
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
998
|
+
//#endregion
|
|
999
|
+
//#region src/query/react/index.d.ts
|
|
1000
|
+
declare const createApi: import("@reduxjs/toolkit/query").CreateApi<typeof import("@reduxjs/toolkit/query").coreModuleName | typeof reactHooksModuleName>;
|
|
1001
|
+
//#endregion
|
|
1009
1002
|
export { ApiProvider, type TypedInfiniteQueryStateSelector, type TypedLazyInfiniteQueryTrigger, type TypedLazyQueryTrigger, type TypedMutationTrigger, type TypedQueryStateSelector, type TypedUseInfiniteQuery, type TypedUseInfiniteQueryHookResult, type TypedUseInfiniteQueryState, type TypedUseInfiniteQueryStateOptions, type TypedUseInfiniteQueryStateResult, type TypedUseInfiniteQuerySubscription, type TypedUseInfiniteQuerySubscriptionResult, type TypedUseLazyQuery, type TypedUseLazyQueryStateResult, type TypedUseLazyQuerySubscription, type TypedUseMutation, type TypedUseMutationResult, type TypedUseMutationStateOptions, type TypedUseQuery, type TypedUseQueryHookResult, type TypedUseQueryState, type TypedUseQueryStateOptions, type TypedUseQueryStateResult, type TypedUseQuerySubscription, type TypedUseQuerySubscriptionOptions, type TypedUseQuerySubscriptionResult, createApi, reactHooksModule };
|