@@ -436,6 +436,52 @@ export type UseQueryStateOptions<
436
436
* This is particularly useful for setting default query behaviors such as
437
437
* refetching strategies, which can be overridden as needed.
438
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
+ * ```
439
485
*
440
486
* @template ResultType - The type of the result `data` returned by the query.
441
487
* @template QueryArg - The type of the argument passed into the query.
0 commit comments