import { QueryStatus, QuerySubState, SubscriptionOptions, QueryKeys } from '../core/apiState'; import { EndpointDefinitions, MutationDefinition, QueryDefinition, QueryArgFrom, ResultTypeFrom } from '../endpointDefinitions'; import { QueryResultSelectorResult, MutationResultSelectorResult } from '../core/buildSelectors'; import { QueryActionCreatorResult } from '../core/buildInitiate'; import { Api } from '../apiTypes'; import { Id, NoInfer, Override } from '../tsHelpers'; import { CoreModule, PrefetchOptions } from '../core/module'; import { ReactHooksModuleOptions } from './module'; import { UninitializedValue } from '../constants'; export interface QueryHooks> { useQuery: UseQuery; useLazyQuery: UseLazyQuery; useQuerySubscription: UseQuerySubscription; useLazyQuerySubscription: UseLazyQuerySubscription; useQueryState: UseQueryState; } export interface MutationHooks> { useMutation: UseMutation; } /** * test description here */ export declare type UseQuery> = = UseQueryStateDefaultResult>(arg: QueryArgFrom, options?: UseQuerySubscriptionOptions & UseQueryStateOptions) => UseQueryStateResult & ReturnType>; interface UseQuerySubscriptionOptions extends SubscriptionOptions { /** * Prevents a query from automatically running. * * @remarks * When skip is true: * * - **If the query has cached data:** * * The cached data **will not be used** on the initial load, and will ignore updates from any identical query until the `skip` condition is removed * * The query will have a status of `uninitialized` * * If `skip: false` is set after skipping the initial load, the cached result will be used * - **If the query does not have cached data:** * * The query will have a status of `uninitialized` * * The query will not exist in the state when viewed with the dev tools * * The query will not automatically fetch on mount * * The query will not automatically run when additional components with the same query are added that do run * * @example * ```ts * // codeblock-meta title="Skip example" * const Pokemon = ({ name, skip }: { name: string; skip: boolean }) => { * const { data, error, status } = useGetPokemonByNameQuery(name, { * skip, * }); * * return ( *
* {name} - {status} *
* ); * }; * ``` */ skip?: boolean; /** * Defaults to `false`. This setting allows you to control whether if a cached result is already available, RTK Query will only serve a cached result, or if it should `refetch` when set to `true` or if an adequate amount of time has passed since the last successful query result. * - `false` - Will not cause a query to be performed _unless_ it does not exist yet. * - `true` - Will always refetch when a new subscriber to a query is added. Behaves the same as calling the `refetch` callback or passing `forceRefetch: true` in the action creator. * - `number` - **Value is in seconds**. If a number is provided and there is an existing query in the cache, it will compare the current time vs the last fulfilled timestamp, and only refetch if enough time has elapsed. * * If you specify this option alongside `skip: true`, this **will not be evaluated** until `skip` is false. */ refetchOnMountOrArgChange?: boolean | number; } export declare type UseQuerySubscription> = (arg: QueryArgFrom, options?: UseQuerySubscriptionOptions) => Pick, 'refetch'>; export declare type UseLazyQueryLastPromiseInfo> = { lastArg: QueryArgFrom; }; export declare type UseLazyQuery> = >(options?: SubscriptionOptions & Omit, 'skip'>) => [(arg: QueryArgFrom) => void, UseQueryStateResult, UseLazyQueryLastPromiseInfo]; export declare type UseLazyQuerySubscription> = (options?: SubscriptionOptions) => [(arg: QueryArgFrom) => void, QueryArgFrom | UninitializedValue]; export declare type QueryStateSelector, D extends QueryDefinition> = (state: QueryResultSelectorResult, lastResult: R | undefined, defaultQueryStateSelector: DefaultQueryStateSelector) => R; export declare type DefaultQueryStateSelector> = (state: QueryResultSelectorResult, lastResult: Pick, 'data'>) => UseQueryStateDefaultResult; export declare type UseQueryState> = >(arg: QueryArgFrom, options?: UseQueryStateOptions) => UseQueryStateResult; export declare type UseQueryStateOptions, R extends Record> = { /** * Prevents a query from automatically running. * * @remarks * When skip is true: * * - **If the query has cached data:** * * The cached data **will not be used** on the initial load, and will ignore updates from any identical query until the `skip` condition is removed * * The query will have a status of `uninitialized` * * If `skip: false` is set after skipping the initial load, the cached result will be used * - **If the query does not have cached data:** * * The query will have a status of `uninitialized` * * The query will not exist in the state when viewed with the dev tools * * The query will not automatically fetch on mount * * The query will not automatically run when additional components with the same query are added that do run * * @example * ```ts * // codeblock-meta title="Skip example" * const Pokemon = ({ name, skip }: { name: string; skip: boolean }) => { * const { data, error, status } = useGetPokemonByNameQuery(name, { * skip, * }); * * return ( *
* {name} - {status} *
* ); * }; * ``` */ skip?: boolean; /** * `selectFromResult` allows you to get a specific segment from a query result in a performant manner. * When using this feature, the component will not rerender unless the underlying data of the selected item has changed. * If the selected item is one element in a larger collection, it will disregard changes to elements in the same collection. * * @example * ```ts * // codeblock-meta title="Using selectFromResult to extract a single result" * function PostsList() { * const { data: posts } = api.useGetPostsQuery(); * * return ( *
    * {posts?.data?.map((post) => ( * * ))} *
* ); * } * * function PostById({ id }: { id: number }) { * // Will select the post with the given id, and will only rerender if the given posts data changes * const { post } = api.useGetPostsQuery(undefined, { * selectFromResult: ({ data }) => ({ post: data?.find((post) => post.id === id) }), * }); * * return
  • {post?.name}
  • ; * } * ``` */ selectFromResult?: QueryStateSelector; }; export declare type UseQueryStateResult<_ extends QueryDefinition, R> = NoInfer; declare type UseQueryStateBaseResult> = QuerySubState & { /** * Query has not started yet. */ isUninitialized: false; /** * Query is currently loading for the first time. No data yet. */ isLoading: false; /** * Query is currently fetching, but might have data from an earlier request. */ isFetching: false; /** * Query has data from a successful load. */ isSuccess: false; /** * Query is currently in "error" state. */ isError: false; }; declare type UseQueryStateDefaultResult> = Id, { status: QueryStatus.uninitialized; }>, { isUninitialized: true; }> | Override, { isLoading: true; isFetching: boolean; data: undefined; } | ({ isSuccess: true; isFetching: boolean; error: undefined; } & Required, 'data' | 'fulfilledTimeStamp'>>) | ({ isError: true; } & Required, 'error'>>)>> & { /** * @deprecated will be removed in the next version * please use the `isLoading`, `isFetching`, `isSuccess`, `isError` * and `isUninitialized` flags instead */ status: QueryStatus; }; export declare type MutationStateSelector, D extends MutationDefinition> = (state: MutationResultSelectorResult, defaultMutationStateSelector: DefaultMutationStateSelector) => R; export declare type DefaultMutationStateSelector> = (state: MutationResultSelectorResult) => MutationResultSelectorResult; export declare type UseMutationStateOptions, R extends Record> = { selectFromResult?: MutationStateSelector; }; export declare type UseMutationStateResult<_ extends MutationDefinition, R> = NoInfer; export declare type UseMutation> = = MutationResultSelectorResult>(options?: UseMutationStateOptions) => [ (arg: QueryArgFrom) => { /** * Unwraps a mutation call to provide the raw response/error. * * @remarks * If you need to access the error or success payload immediately after a mutation, you can chain .unwrap(). * * @example * ```ts * // codeblock-meta title="Using .unwrap" * addPost({ id: 1, name: 'Example' }) * .unwrap() * .then((payload) => console.log('fulfilled', payload)) * .catch((error) => console.error('rejected', error)); * ``` * * @example * ```ts * // codeblock-meta title="Using .unwrap with async await" * try { * const payload = await addPost({ id: 1, name: 'Example' }).unwrap(); * console.log('fulfilled', payload) * } catch (error) { * console.error('rejected', error); * } * ``` */ unwrap: () => Promise>; }, UseMutationStateResult ]; /** * * @param opts.api - An API with defined endpoints to create hooks for * @param opts.moduleOptions.batch - The version of the `batchedUpdates` function to be used * @param opts.moduleOptions.useDispatch - The version of the `useDispatch` hook to be used * @param opts.moduleOptions.useSelector - The version of the `useSelector` hook to be used * @returns An object containing functions to generate hooks based on an endpoint */ export declare function buildHooks({ api, moduleOptions: { batch, useDispatch, useSelector }, }: { api: Api; moduleOptions: Required; }): { buildQueryHooks: (name: string) => QueryHooks; buildMutationHook: (name: string) => UseMutation; usePrefetch: >(endpointName: EndpointName, defaultOptions?: PrefetchOptions | undefined) => (arg: any, options?: PrefetchOptions | undefined) => void; }; export {}; //# sourceMappingURL=buildHooks.d.ts.map