@@ -357,6 +357,9 @@ export type TypedUseQueryState<
357
357
QueryDefinition < QueryArg , BaseQuery , string , ResultType , string >
358
358
>
359
359
360
+ /**
361
+ * @internal
362
+ */
360
363
export type UseQueryStateOptions <
361
364
D extends QueryDefinition < any , any , any , any > ,
362
365
R extends Record < string , any > ,
@@ -427,6 +430,79 @@ export type UseQueryStateOptions<
427
430
selectFromResult ?: QueryStateSelector < R , D >
428
431
}
429
432
433
+ /**
434
+ * Provides a way to define a "pre-typed" version of
435
+ * {@linkcode UseQueryStateOptions} with specific options for a given query.
436
+ * This is particularly useful for setting default query behaviors such as
437
+ * refetching strategies, which can be overridden as needed.
438
+ *
439
+ * @example
440
+ * <caption>#### __Create a `useQuery` hook with default options__</caption>
441
+ *
442
+ * ```ts
443
+ * import type {
444
+ * SubscriptionOptions,
445
+ * TypedUseQueryStateOptions,
446
+ * } from '@reduxjs/toolkit/query/react'
447
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
448
+ *
449
+ * type Post = {
450
+ * id: number
451
+ * name: string
452
+ * }
453
+ *
454
+ * const api = createApi({
455
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
456
+ * tagTypes: ['Post'],
457
+ * endpoints: (build) => ({
458
+ * getPosts: build.query<Post[], void>({
459
+ * query: () => 'posts',
460
+ * }),
461
+ * }),
462
+ * })
463
+ *
464
+ * const { useGetPostsQuery } = api
465
+ *
466
+ * export const useGetPostsQueryWithDefaults = <
467
+ * SelectedResult extends Record<string, any>,
468
+ * >(
469
+ * overrideOptions: TypedUseQueryStateOptions<
470
+ * Post[],
471
+ * void,
472
+ * ReturnType<typeof fetchBaseQuery>,
473
+ * SelectedResult
474
+ * > &
475
+ * SubscriptionOptions,
476
+ * ) =>
477
+ * useGetPostsQuery(undefined, {
478
+ * // Insert default options here
479
+ *
480
+ * refetchOnMountOrArgChange: true,
481
+ * refetchOnFocus: true,
482
+ * ...overrideOptions,
483
+ * })
484
+ * ```
485
+ *
486
+ * @template ResultType - The type of the result `data` returned by the query.
487
+ * @template QueryArg - The type of the argument passed into the query.
488
+ * @template BaseQuery - The type of the base query function being used.
489
+ * @template SelectedResult - The type of the selected result returned by the __`selectFromResult`__ function.
490
+ *
491
+ * @since 2.7.8
492
+ * @public
493
+ */
494
+ export type TypedUseQueryStateOptions <
495
+ ResultType ,
496
+ QueryArg ,
497
+ BaseQuery extends BaseQueryFn ,
498
+ SelectedResult extends Record < string , any > = UseQueryStateDefaultResult <
499
+ QueryDefinition < QueryArg , BaseQuery , string , ResultType , string >
500
+ > ,
501
+ > = UseQueryStateOptions <
502
+ QueryDefinition < QueryArg , BaseQuery , string , ResultType , string > ,
503
+ SelectedResult
504
+ >
505
+
430
506
export type UseQueryStateResult <
431
507
_ extends QueryDefinition < any , any , any , any > ,
432
508
R ,
0 commit comments