module.d.ts 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import type { MutationHooks, QueryHooks } from './buildHooks';
  2. import type { EndpointDefinitions, QueryDefinition, MutationDefinition, QueryArgFrom } from '@reduxjs/toolkit/query';
  3. import type { Module } from '../apiTypes';
  4. import type { BaseQueryFn } from '@reduxjs/toolkit/query';
  5. import type { HooksWithUniqueNames } from './namedHooks';
  6. import type { QueryKeys } from '../core/apiState';
  7. import type { PrefetchOptions } from '../core/module';
  8. export declare const reactHooksModuleName: unique symbol;
  9. export declare type ReactHooksModule = typeof reactHooksModuleName;
  10. declare module '@reduxjs/toolkit/query' {
  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. }
  26. declare type RR = typeof import('react-redux');
  27. export 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. */
  78. export declare const reactHooksModule: ({ batch, useDispatch, useSelector, useStore, unstable__sideEffectsInRender, }?: ReactHooksModuleOptions) => Module<ReactHooksModule>;
  79. export {};