UNPKG

3.4 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 './namedHooks';
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 * Enables performing asynchronous tasks immediately within a render.
46 *
47 * @example
48 *
49 * ```ts
50 * import {
51 * buildCreateApi,
52 * coreModule,
53 * reactHooksModule
54 * } from '@reduxjs/toolkit/query/react'
55 *
56 * const createApi = buildCreateApi(
57 * coreModule(),
58 * reactHooksModule({ unstable__sideEffectsInRender: true })
59 * )
60 * ```
61 */
62 unstable__sideEffectsInRender?: boolean;
63}
64/**
65 * Creates a module that generates react hooks from endpoints, for use with `buildCreateApi`.
66 *
67 * @example
68 * ```ts
69 * const MyContext = React.createContext<ReactReduxContextValue>(null as any);
70 * const customCreateApi = buildCreateApi(
71 * coreModule(),
72 * reactHooksModule({ useDispatch: createDispatchHook(MyContext) })
73 * );
74 * ```
75 *
76 * @returns A module for use with `buildCreateApi`
77 */
78export declare const reactHooksModule: ({ batch, useDispatch, useSelector, useStore, unstable__sideEffectsInRender, }?: ReactHooksModuleOptions) => Module<ReactHooksModule>;
79export {};