@@ -357,6 +357,9 @@ export type TypedUseQueryState<
357357 QueryDefinition < QueryArg , BaseQuery , string , ResultType , string >
358358>
359359
360+ /**
361+ * @internal
362+ */
360363export type UseQueryStateOptions <
361364 D extends QueryDefinition < any , any , any , any > ,
362365 R extends Record < string , any > ,
@@ -427,6 +430,79 @@ export type UseQueryStateOptions<
427430 selectFromResult ?: QueryStateSelector < R , D >
428431}
429432
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+
430506export type UseQueryStateResult <
431507 _ extends QueryDefinition < any , any , any , any > ,
432508 R ,
0 commit comments