@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.
Files changed (93) hide show
  1. package/README.md +4 -4
  2. package/changes.json +3 -3
  3. package/dist/cjs/redux-toolkit.development.cjs +1755 -2247
  4. package/dist/cjs/redux-toolkit.development.cjs.map +1 -1
  5. package/dist/cjs/redux-toolkit.production.min.cjs +1 -2
  6. package/dist/cjs/redux-toolkit.production.min.cjs.map +1 -1
  7. package/dist/index.d.mts +1496 -1525
  8. package/dist/index.d.ts +1496 -1525
  9. package/dist/query/cjs/rtk-query.development.cjs +2059 -2990
  10. package/dist/query/cjs/rtk-query.development.cjs.map +1 -1
  11. package/dist/query/cjs/rtk-query.production.min.cjs +1 -1
  12. package/dist/query/cjs/rtk-query.production.min.cjs.map +1 -1
  13. package/dist/query/index.d.mts +2300 -2308
  14. package/dist/query/index.d.ts +2300 -2308
  15. package/dist/query/react/cjs/rtk-query-react.development.cjs +609 -714
  16. package/dist/query/react/cjs/rtk-query-react.development.cjs.map +1 -1
  17. package/dist/query/react/cjs/rtk-query-react.production.min.cjs +1 -1
  18. package/dist/query/react/cjs/rtk-query-react.production.min.cjs.map +1 -1
  19. package/dist/query/react/index.d.mts +516 -523
  20. package/dist/query/react/index.d.ts +516 -523
  21. package/dist/query/react/rtk-query-react.browser.mjs +1 -1
  22. package/dist/query/react/rtk-query-react.browser.mjs.map +1 -1
  23. package/dist/query/react/rtk-query-react.legacy-esm.js +672 -714
  24. package/dist/query/react/rtk-query-react.legacy-esm.js.map +1 -1
  25. package/dist/query/react/rtk-query-react.modern.mjs +586 -679
  26. package/dist/query/react/rtk-query-react.modern.mjs.map +1 -1
  27. package/dist/query/rtk-query.browser.mjs +1 -1
  28. package/dist/query/rtk-query.browser.mjs.map +1 -1
  29. package/dist/query/rtk-query.legacy-esm.js +2175 -3014
  30. package/dist/query/rtk-query.legacy-esm.js.map +1 -1
  31. package/dist/query/rtk-query.modern.mjs +2052 -2949
  32. package/dist/query/rtk-query.modern.mjs.map +1 -1
  33. package/dist/react/cjs/redux-toolkit-react.development.cjs +30 -51
  34. package/dist/react/cjs/redux-toolkit-react.development.cjs.map +1 -1
  35. package/dist/react/cjs/redux-toolkit-react.production.min.cjs +1 -1
  36. package/dist/react/cjs/redux-toolkit-react.production.min.cjs.map +1 -1
  37. package/dist/react/index.d.mts +12 -15
  38. package/dist/react/index.d.ts +12 -15
  39. package/dist/react/redux-toolkit-react.browser.mjs +1 -1
  40. package/dist/react/redux-toolkit-react.browser.mjs.map +1 -1
  41. package/dist/react/redux-toolkit-react.legacy-esm.js +83 -44
  42. package/dist/react/redux-toolkit-react.legacy-esm.js.map +1 -1
  43. package/dist/react/redux-toolkit-react.modern.mjs +23 -25
  44. package/dist/react/redux-toolkit-react.modern.mjs.map +1 -1
  45. package/dist/redux-toolkit.browser.mjs +1 -2
  46. package/dist/redux-toolkit.browser.mjs.map +1 -1
  47. package/dist/redux-toolkit.legacy-esm.js +1748 -2201
  48. package/dist/redux-toolkit.legacy-esm.js.map +1 -1
  49. package/dist/redux-toolkit.modern.mjs +1670 -2171
  50. package/dist/redux-toolkit.modern.mjs.map +1 -1
  51. package/package.json +17 -33
  52. package/skills/build-modern-redux-apps/modern-redux/SKILL.md +23 -14
  53. package/skills/build-modern-redux-apps/modern-redux/references/store-lifetime.md +6 -6
  54. package/skills/build-modern-redux-apps/redux-dataflow/SKILL.md +13 -10
  55. package/skills/evolve-and-diagnose-redux-apps/debug-redux-toolkit-apps/SKILL.md +6 -6
  56. package/skills/evolve-and-diagnose-redux-apps/migrate-to-modern-redux/SKILL.md +7 -8
  57. package/skills/manage-server-data/adopt-rtk-query/SKILL.md +13 -11
  58. package/skills/model-redux-state/build-slices-and-selectors/SKILL.md +26 -14
  59. package/skills/model-redux-state/design-state-ownership/SKILL.md +11 -12
  60. package/skills/model-redux-state/design-state-ownership/references/state-ownership.md +6 -6
  61. package/skills/orchestrate-side-effects/handle-side-effects/SKILL.md +27 -23
  62. package/skills/orchestrate-side-effects/handle-side-effects/references/listener-workflows.md +4 -4
  63. package/src/autoBatchEnhancer.ts +5 -3
  64. package/src/combineSlices.ts +5 -5
  65. package/src/createAction.ts +11 -6
  66. package/src/createAsyncThunk.ts +14 -2
  67. package/src/createReducer.ts +1 -1
  68. package/src/createSlice.ts +9 -4
  69. package/src/dynamicMiddleware/index.ts +21 -5
  70. package/src/entities/models.ts +2 -1
  71. package/src/entities/sorted_state_adapter.ts +35 -24
  72. package/src/entities/unsorted_state_adapter.ts +1 -1
  73. package/src/immutableStateInvariantMiddleware.ts +34 -5
  74. package/src/listenerMiddleware/types.ts +10 -10
  75. package/src/mapBuilders.ts +2 -5
  76. package/src/matchers.ts +7 -1
  77. package/src/query/core/apiState.ts +1 -1
  78. package/src/query/core/buildInitiate.ts +19 -15
  79. package/src/query/core/buildMiddleware/cacheLifecycle.ts +3 -1
  80. package/src/query/core/buildMiddleware/index.ts +1 -1
  81. package/src/query/core/buildMiddleware/invalidationByTags.ts +4 -1
  82. package/src/query/core/buildMiddleware/polling.ts +12 -3
  83. package/src/query/core/buildMiddleware/types.ts +5 -2
  84. package/src/query/core/buildSlice.ts +2 -2
  85. package/src/query/core/buildThunks.ts +19 -0
  86. package/src/query/core/module.ts +9 -3
  87. package/src/query/createApi.ts +4 -1
  88. package/src/query/endpointDefinitions.ts +15 -9
  89. package/src/query/fetchBaseQuery.ts +1 -1
  90. package/src/query/react/buildHooks.ts +54 -51
  91. package/src/query/react/namedHooks.ts +28 -24
  92. package/src/query/utils/isAbsoluteUrl.ts +8 -3
  93. package/src/serializableStateInvariantMiddleware.ts +1 -1
@@ -1,35 +1,40 @@
1
- import * as _reduxjs_toolkit_query from '@reduxjs/toolkit/query';
2
- import { QueryDefinition, TSHelpersId, TSHelpersOverride, QuerySubState, ResultTypeFrom, QueryStatus, QueryArgFrom, SkipToken, SubscriptionOptions, QueryActionCreatorResult, MutationDefinition, MutationResultSelectorResult, MutationActionCreatorResult, InfiniteQueryDefinition, InfiniteQuerySubState, PageParamFrom, InfiniteQueryArgFrom, InfiniteQueryActionCreatorResult, BaseQueryFn, EndpointDefinitions, DefinitionType, QueryKeys, PrefetchOptions, Module, Api, setupListeners } from '@reduxjs/toolkit/query';
3
- export * from '@reduxjs/toolkit/query';
4
- import * as react_redux from 'react-redux';
5
- import { ReactReduxContextValue } from 'react-redux';
6
- import { CreateSelectorFunction } from 'reselect';
7
- import * as React from 'react';
8
- import { Context } from 'react';
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
- pages: Array<DataType>;
12
- pageParams: Array<PageParam>;
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
- useQuery: UseQuery<Definition>;
21
- useLazyQuery: UseLazyQuery<Definition>;
22
- useQuerySubscription: UseQuerySubscription<Definition>;
23
- useLazyQuerySubscription: UseLazyQuerySubscription<Definition>;
24
- useQueryState: UseQueryState<Definition>;
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
- useInfiniteQuery: UseInfiniteQuery<Definition>;
28
- useInfiniteQuerySubscription: UseInfiniteQuerySubscription<Definition>;
29
- useInfiniteQueryState: UseInfiniteQueryState<Definition>;
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
- useMutation: UseMutation<Definition>;
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
- * Prevents a query from automatically running.
60
- *
61
- * @remarks
62
- * When `skip` is true (or `skipToken` is passed in as `arg`):
63
- *
64
- * - **If the query has cached data:**
65
- * * 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
66
- * * The query will have a status of `uninitialized`
67
- * * If `skip: false` is set after the initial load, the cached result will be used
68
- * - **If the query does not have cached data:**
69
- * * The query will have a status of `uninitialized`
70
- * * The query will not exist in the state when viewed with the dev tools
71
- * * The query will not automatically fetch on mount
72
- * * The query will not automatically run when additional components with the same query are added that do run
73
- *
74
- * @example
75
- * ```tsx
76
- * // codeblock-meta no-transpile title="Skip example"
77
- * const Pokemon = ({ name, skip }: { name: string; skip: boolean }) => {
78
- * const { data, error, status } = useGetPokemonByNameQuery(name, {
79
- * skip,
80
- * });
81
- *
82
- * return (
83
- * <div>
84
- * {name} - {status}
85
- * </div>
86
- * );
87
- * };
88
- * ```
89
- */
90
- skip?: boolean;
91
- /**
92
- * 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.
93
- * - `false` - Will not cause a query to be performed _unless_ it does not exist yet.
94
- * - `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.
95
- * - `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.
96
- *
97
- * If you specify this option alongside `skip: true`, this **will not be evaluated** until `skip` is false.
98
- */
99
- refetchOnMountOrArgChange?: boolean | number;
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
- lastArg: QueryArgFrom<D>;
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
- * Resets the hook state to its initial `uninitialized` state.
163
- * This will also remove the last result from the cache.
164
- */
165
- reset: () => void;
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
- * Triggers a lazy query.
175
- *
176
- * By default, this will start a new request even if there is already a value in the cache.
177
- * 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`.
178
- *
179
- * @remarks
180
- * If you need to access the error or success payload immediately after a lazy query, you can chain .unwrap().
181
- *
182
- * @example
183
- * ```ts
184
- * // codeblock-meta title="Using .unwrap with async await"
185
- * try {
186
- * const payload = await getUserById(1).unwrap();
187
- * console.log('fulfilled', payload);
188
- * } catch (error) {
189
- * console.error('rejected', error);
190
- * }
191
- * ```
192
- */
193
- (arg: QueryArgFrom<D>, preferCacheValue?: boolean): QueryActionCreatorResult<D>;
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
- LazyQueryTrigger<D>,
209
- QueryArgFrom<D> | UninitializedValue,
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
- * Prevents a query from automatically running.
327
- *
328
- * @remarks
329
- * When skip is true:
330
- *
331
- * - **If the query has cached data:**
332
- * * 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
333
- * * The query will have a status of `uninitialized`
334
- * * If `skip: false` is set after skipping the initial load, the cached result will be used
335
- * - **If the query does not have cached data:**
336
- * * The query will have a status of `uninitialized`
337
- * * The query will not exist in the state when viewed with the dev tools
338
- * * The query will not automatically fetch on mount
339
- * * The query will not automatically run when additional components with the same query are added that do run
340
- *
341
- * @example
342
- * ```tsx
343
- * // codeblock-meta title="Skip example"
344
- * const Pokemon = ({ name, skip }: { name: string; skip: boolean }) => {
345
- * const { data, error, status } = useGetPokemonByNameQuery(name, {
346
- * skip,
347
- * });
348
- *
349
- * return (
350
- * <div>
351
- * {name} - {status}
352
- * </div>
353
- * );
354
- * };
355
- * ```
356
- */
357
- skip?: boolean;
358
- /**
359
- * `selectFromResult` allows you to get a specific segment from a query result in a performant manner.
360
- * When using this feature, the component will not rerender unless the underlying data of the selected item has changed.
361
- * If the selected item is one element in a larger collection, it will disregard changes to elements in the same collection.
362
- *
363
- * @example
364
- * ```tsx
365
- * // codeblock-meta title="Using selectFromResult to extract a single result"
366
- * function PostsList() {
367
- * const { data: posts } = api.useGetPostsQuery();
368
- *
369
- * return (
370
- * <ul>
371
- * {posts?.data?.map((post) => (
372
- * <PostById key={post.id} id={post.id} />
373
- * ))}
374
- * </ul>
375
- * );
376
- * }
377
- *
378
- * function PostById({ id }: { id: number }) {
379
- * // Will select the post with the given id, and will only rerender if the given posts data changes
380
- * const { post } = api.useGetPostsQuery(undefined, {
381
- * selectFromResult: ({ data }) => ({
382
- * post: data?.find((post) => post.id === id),
383
- * }),
384
- * });
385
- *
386
- * return <li>{post?.name}</li>;
387
- * }
388
- * ```
389
- */
390
- selectFromResult?: QueryStateSelector<R, D>;
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
- * Where `data` tries to hold data as much as possible, also reusing
463
- * data from the last arguments passed into the hook, this property
464
- * will always contain the received data from the query, for the current query arguments.
465
- */
466
- currentData?: ResultTypeFrom<D>;
467
- /**
468
- * Query has not started yet.
469
- */
470
- isUninitialized: false;
471
- /**
472
- * Query is currently loading for the first time. No data yet.
473
- */
474
- isLoading: false;
475
- /**
476
- * Query is currently fetching, but might have data from an earlier request.
477
- */
478
- isFetching: false;
479
- /**
480
- * Query has data from a successful load.
481
- */
482
- isSuccess: false;
483
- /**
484
- * Query is currently in "error" state.
485
- */
486
- isError: false;
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
- status: QueryStatus.uninitialized;
486
+ status: QueryStatus.uninitialized;
490
487
  }>, {
491
- isUninitialized: true;
488
+ isUninitialized: true;
492
489
  }>;
493
490
  type UseQueryStateLoading<D extends QueryDefinition<any, any, any, any>> = TSHelpersOverride<UseQueryStateBaseResult<D>, {
494
- isLoading: true;
495
- isFetching: boolean;
496
- data: undefined;
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
- isSuccess: true;
500
- isFetching: true;
501
- error: undefined;
496
+ isSuccess: true;
497
+ isFetching: true;
498
+ error: undefined;
502
499
  } & {
503
- data: ResultTypeFrom<D>;
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
- isSuccess: true;
507
- isFetching: false;
508
- error: undefined;
503
+ isSuccess: true;
504
+ isFetching: false;
505
+ error: undefined;
509
506
  } & {
510
- data: ResultTypeFrom<D>;
511
- currentData: ResultTypeFrom<D>;
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
- isError: true;
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
- * @deprecated Included for completeness, but discouraged.
519
- * Please use the `isLoading`, `isFetching`, `isSuccess`, `isError`
520
- * and `isUninitialized` flags instead
521
- */
522
- status: QueryStatus;
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
- * Triggers a lazy query.
527
- *
528
- * By default, this will start a new request even if there is already a value in the cache.
529
- * 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`.
530
- *
531
- * @remarks
532
- * If you need to access the error or success payload immediately after a lazy query, you can chain .unwrap().
533
- *
534
- * @example
535
- * ```ts
536
- * // codeblock-meta title="Using .unwrap with async await"
537
- * try {
538
- * const payload = await getUserById(1).unwrap();
539
- * console.log('fulfilled', payload);
540
- * } catch (error) {
541
- * console.error('rejected', error);
542
- * }
543
- * ```
544
- */
545
- (arg: QueryArgFrom<D>, direction: InfiniteQueryDirection): InfiniteQueryActionCreatorResult<D>;
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
- * Prevents a query from automatically running.
551
- *
552
- * @remarks
553
- * When `skip` is true (or `skipToken` is passed in as `arg`):
554
- *
555
- * - **If the query has cached data:**
556
- * * 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
557
- * * The query will have a status of `uninitialized`
558
- * * If `skip: false` is set after the initial load, the cached result will be used
559
- * - **If the query does not have cached data:**
560
- * * The query will have a status of `uninitialized`
561
- * * The query will not exist in the state when viewed with the dev tools
562
- * * The query will not automatically fetch on mount
563
- * * The query will not automatically run when additional components with the same query are added that do run
564
- *
565
- * @example
566
- * ```tsx
567
- * // codeblock-meta no-transpile title="Skip example"
568
- * const Pokemon = ({ name, skip }: { name: string; skip: boolean }) => {
569
- * const { data, error, status } = useGetPokemonByNameQuery(name, {
570
- * skip,
571
- * });
572
- *
573
- * return (
574
- * <div>
575
- * {name} - {status}
576
- * </div>
577
- * );
578
- * };
579
- * ```
580
- */
581
- skip?: boolean;
582
- /**
583
- * 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.
584
- * - `false` - Will not cause a query to be performed _unless_ it does not exist yet.
585
- * - `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.
586
- * - `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.
587
- *
588
- * If you specify this option alongside `skip: true`, this **will not be evaluated** until `skip` is false.
589
- */
590
- refetchOnMountOrArgChange?: boolean | number;
591
- initialPageParam?: PageParamFrom<D>;
592
- /**
593
- * Defaults to `true`. When this is `true` and an infinite query endpoint is refetched
594
- * (due to tag invalidation, polling, arg change configuration, or manual refetching),
595
- * RTK Query will try to sequentially refetch all pages currently in the cache.
596
- * When `false` only the first page will be refetched.
597
- *
598
- * This option applies to all automatic refetches for this subscription (polling, tag invalidation, etc.).
599
- * It can be overridden on a per-call basis using the `refetch()` method.
600
- */
601
- refetchCachedPages?: boolean;
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
- refetch: (options?: Pick<UseInfiniteQuerySubscriptionOptions<D>, 'refetchCachedPages'>) => InfiniteQueryActionCreatorResult<D>;
606
- trigger: LazyInfiniteQueryTrigger<D>;
607
- fetchNextPage: () => InfiniteQueryActionCreatorResult<D>;
608
- fetchPreviousPage: () => InfiniteQueryActionCreatorResult<D>;
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
- * Prevents a query from automatically running.
676
- *
677
- * @remarks
678
- * When skip is true:
679
- *
680
- * - **If the query has cached data:**
681
- * * 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
682
- * * The query will have a status of `uninitialized`
683
- * * If `skip: false` is set after skipping the initial load, the cached result will be used
684
- * - **If the query does not have cached data:**
685
- * * The query will have a status of `uninitialized`
686
- * * The query will not exist in the state when viewed with the dev tools
687
- * * The query will not automatically fetch on mount
688
- * * The query will not automatically run when additional components with the same query are added that do run
689
- *
690
- * @example
691
- * ```tsx
692
- * // codeblock-meta title="Skip example"
693
- * const Pokemon = ({ name, skip }: { name: string; skip: boolean }) => {
694
- * const { data, error, status } = useGetPokemonByNameQuery(name, {
695
- * skip,
696
- * });
697
- *
698
- * return (
699
- * <div>
700
- * {name} - {status}
701
- * </div>
702
- * );
703
- * };
704
- * ```
705
- */
706
- skip?: boolean;
707
- /**
708
- * `selectFromResult` allows you to get a specific segment from a query result in a performant manner.
709
- * When using this feature, the component will not rerender unless the underlying data of the selected item has changed.
710
- * If the selected item is one element in a larger collection, it will disregard changes to elements in the same collection.
711
- * Note that this should always return an object (not a primitive), as RTKQ adds fields to the return value.
712
- *
713
- * @example
714
- * ```tsx
715
- * // codeblock-meta title="Using selectFromResult to extract a single result"
716
- * function PostsList() {
717
- * const { data: posts } = api.useGetPostsQuery();
718
- *
719
- * return (
720
- * <ul>
721
- * {posts?.data?.map((post) => (
722
- * <PostById key={post.id} id={post.id} />
723
- * ))}
724
- * </ul>
725
- * );
726
- * }
727
- *
728
- * function PostById({ id }: { id: number }) {
729
- * // Will select the post with the given id, and will only rerender if the given posts data changes
730
- * const { post } = api.useGetPostsQuery(undefined, {
731
- * selectFromResult: ({ data }) => ({
732
- * post: data?.find((post) => post.id === id),
733
- * }),
734
- * });
735
- *
736
- * return <li>{post?.name}</li>;
737
- * }
738
- * ```
739
- */
740
- selectFromResult?: InfiniteQueryStateSelector<R, D>;
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
- * Where `data` tries to hold data as much as possible, also reusing
748
- * data from the last arguments passed into the hook, this property
749
- * will always contain the received data from the query, for the current query arguments.
750
- */
751
- currentData?: InfiniteData<ResultTypeFrom<D>, PageParamFrom<D>>;
752
- /**
753
- * Query has not started yet.
754
- */
755
- isUninitialized: false;
756
- /**
757
- * Query is currently loading for the first time. No data yet.
758
- */
759
- isLoading: false;
760
- /**
761
- * Query is currently fetching, but might have data from an earlier request.
762
- */
763
- isFetching: false;
764
- /**
765
- * Query has data from a successful load.
766
- */
767
- isSuccess: false;
768
- /**
769
- * Query is currently in "error" state.
770
- */
771
- isError: false;
772
- hasNextPage: boolean;
773
- hasPreviousPage: boolean;
774
- isFetchingNextPage: boolean;
775
- isFetchingPreviousPage: boolean;
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
- status: QueryStatus.uninitialized;
777
+ status: QueryStatus.uninitialized;
779
778
  }>, {
780
- isUninitialized: true;
779
+ isUninitialized: true;
781
780
  }> | TSHelpersOverride<UseInfiniteQueryStateBaseResult<D>, {
782
- isLoading: true;
783
- isFetching: boolean;
784
- data: undefined;
781
+ isLoading: true;
782
+ isFetching: boolean;
783
+ data: undefined;
785
784
  } | ({
786
- isSuccess: true;
787
- isFetching: true;
788
- error: undefined;
785
+ isSuccess: true;
786
+ isFetching: true;
787
+ error: undefined;
789
788
  } & Required<Pick<UseInfiniteQueryStateBaseResult<D>, 'data' | 'fulfilledTimeStamp'>>) | ({
790
- isSuccess: true;
791
- isFetching: false;
792
- error: undefined;
789
+ isSuccess: true;
790
+ isFetching: false;
791
+ error: undefined;
793
792
  } & Required<Pick<UseInfiniteQueryStateBaseResult<D>, 'data' | 'fulfilledTimeStamp' | 'currentData'>>) | ({
794
- isError: true;
793
+ isError: true;
795
794
  } & Required<Pick<UseInfiniteQueryStateBaseResult<D>, 'error'>>)>> & {
796
- /**
797
- * @deprecated Included for completeness, but discouraged.
798
- * Please use the `isLoading`, `isFetching`, `isSuccess`, `isError`
799
- * and `isUninitialized` flags instead
800
- */
801
- status: QueryStatus;
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
- selectFromResult?: MutationStateSelector<R, D>;
806
- fixedCacheKey?: string;
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
- originalArgs?: QueryArgFrom<D>;
823
- /**
824
- * Resets the hook state to its initial `uninitialized` state.
825
- * This will also remove the last result from the cache.
826
- */
827
- reset: () => void;
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
- * Triggers the mutation and returns a Promise.
849
- * @remarks
850
- * If you need to access the error or success payload immediately after a mutation, you can chain .unwrap().
851
- *
852
- * @example
853
- * ```ts
854
- * // codeblock-meta title="Using .unwrap with async await"
855
- * try {
856
- * const payload = await addPost({ id: 1, name: 'Example' }).unwrap();
857
- * console.log('fulfilled', payload);
858
- * } catch (error) {
859
- * console.error('rejected', error);
860
- * }
861
- * ```
862
- */
863
- (arg: QueryArgFrom<D>): MutationActionCreatorResult<D>;
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
- type QueryHookNames<Definitions extends EndpointDefinitions> = {
868
- [K in keyof Definitions as Definitions[K] extends {
869
- type: DefinitionType.query;
870
- } ? `use${Capitalize<K & string>}Query` : never]: UseQuery<Extract<Definitions[K], QueryDefinition<any, any, any, any>>>;
871
- };
872
- type LazyQueryHookNames<Definitions extends EndpointDefinitions> = {
873
- [K in keyof Definitions as Definitions[K] extends {
874
- type: DefinitionType.query;
875
- } ? `useLazy${Capitalize<K & string>}Query` : never]: UseLazyQuery<Extract<Definitions[K], QueryDefinition<any, any, any, any>>>;
876
- };
877
- type InfiniteQueryHookNames<Definitions extends EndpointDefinitions> = {
878
- [K in keyof Definitions as Definitions[K] extends {
879
- type: DefinitionType.infinitequery;
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
- interface ApiModules<BaseQuery extends BaseQueryFn, Definitions extends EndpointDefinitions, ReducerPath extends string, TagTypes extends string> {
893
- [reactHooksModuleName]: {
894
- /**
895
- * Endpoints based on the input endpoints provided to `createApi`, containing `select`, `hooks` and `action matchers`.
896
- */
897
- endpoints: {
898
- [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;
899
- };
900
- /**
901
- * A hook that accepts a string endpoint name, and provides a callback that when called, pre-fetches the data for that endpoint.
902
- */
903
- usePrefetch<EndpointName extends QueryKeys<Definitions>>(endpointName: EndpointName, options?: PrefetchOptions): (arg: QueryArgFrom<Definitions[EndpointName]>, options?: PrefetchOptions) => void;
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 react_redux;
898
+ type RR = typeof import('react-redux');
908
899
  interface ReactHooksModuleOptions {
909
- /**
910
- * The hooks from React Redux to be used
911
- */
912
- hooks?: {
913
- /**
914
- * The version of the `useDispatch` hook to be used
915
- */
916
- useDispatch: RR['useDispatch'];
917
- /**
918
- * The version of the `useSelector` hook to be used
919
- */
920
- useSelector: RR['useSelector'];
921
- /**
922
- * The version of the `useStore` hook to be used
923
- */
924
- useStore: RR['useStore'];
925
- };
926
- /**
927
- * The version of the `batchedUpdates` function to be used
928
- */
929
- batch?: RR['batch'];
930
- /**
931
- * Enables performing asynchronous tasks immediately within a render.
932
- *
933
- * @example
934
- *
935
- * ```ts
936
- * import {
937
- * buildCreateApi,
938
- * coreModule,
939
- * reactHooksModule
940
- * } from '@reduxjs/toolkit/query/react'
941
- *
942
- * const createApi = buildCreateApi(
943
- * coreModule(),
944
- * reactHooksModule({ unstable__sideEffectsInRender: true })
945
- * )
946
- * ```
947
- */
948
- unstable__sideEffectsInRender?: boolean;
949
- /**
950
- * A selector creator (usually from `reselect`, or matching the same signature)
951
- */
952
- createSelector?: CreateSelectorFunction<any, any, any>;
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
- children: any;
1002
- api: Api<any, {}, any, any>;
1003
- setupListeners?: Parameters<typeof setupListeners>[1] | false;
1004
- context?: Context<ReactReduxContextValue | null>;
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
- declare const createApi: _reduxjs_toolkit_query.CreateApi<typeof _reduxjs_toolkit_query.coreModuleName | typeof reactHooksModuleName>;
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 };