UNPKG

2.88 kBTypeScriptView Raw
1import type { MutationHooks, QueryHooks } from './buildHooks';
2import type { EndpointDefinitions, QueryDefinition, MutationDefinition, QueryArgFrom } from '@reduxjs/toolkit/dist/query/endpointDefinitions';
3import type { Module } from '../apiTypes';
4import type { BaseQueryFn } from '@reduxjs/toolkit/dist/query/baseQueryTypes';
5import type { HooksWithUniqueNames } from './versionedTypes';
6import type { QueryKeys } from '../core/apiState';
7import type { PrefetchOptions } from '../core/module';
8export declare const reactHooksModuleName: unique symbol;
9export declare type ReactHooksModule = typeof reactHooksModuleName;
10declare module '@reduxjs/toolkit/dist/query/apiTypes' {
11 interface ApiModules<BaseQuery extends BaseQueryFn, Definitions extends EndpointDefinitions, ReducerPath extends string, TagTypes extends string> {
12 [reactHooksModuleName]: {
13 /**
14 * Endpoints based on the input endpoints provided to `createApi`, containing `select`, `hooks` and `action matchers`.
15 */
16 endpoints: {
17 [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]> : never;
18 };
19 /**
20 * A hook that accepts a string endpoint name, and provides a callback that when called, pre-fetches the data for that endpoint.
21 */
22 usePrefetch<EndpointName extends QueryKeys<Definitions>>(endpointName: EndpointName, options?: PrefetchOptions): (arg: QueryArgFrom<Definitions[EndpointName]>, options?: PrefetchOptions) => void;
23 } & HooksWithUniqueNames<Definitions>;
24 }
25}
26declare type RR = typeof import('react-redux');
27export interface ReactHooksModuleOptions {
28 /**
29 * The version of the `batchedUpdates` function to be used
30 */
31 batch?: RR['batch'];
32 /**
33 * The version of the `useDispatch` hook to be used
34 */
35 useDispatch?: RR['useDispatch'];
36 /**
37 * The version of the `useSelector` hook to be used
38 */
39 useSelector?: RR['useSelector'];
40 /**
41 * The version of the `useStore` hook to be used
42 */
43 useStore?: RR['useStore'];
44}
45/**
46 * Creates a module that generates react hooks from endpoints, for use with `buildCreateApi`.
47 *
48 * @example
49 * ```ts
50 * const MyContext = React.createContext<ReactReduxContextValue>(null as any);
51 * const customCreateApi = buildCreateApi(
52 * coreModule(),
53 * reactHooksModule({ useDispatch: createDispatchHook(MyContext) })
54 * );
55 * ```
56 *
57 * @returns A module for use with `buildCreateApi`
58 */
59export declare const reactHooksModule: ({ batch, useDispatch, useSelector, useStore, }?: ReactHooksModuleOptions) => Module<ReactHooksModule>;
60export {};