import type { LoadingState } from 'robodux'; import type { QueryState } from './slice'; declare type ActionFn

= (p: P) => { toString: () => string; }; declare type ActionFnSimple = () => { toString: () => string; }; interface SagaAction

{ type: string; payload: { key: string; options: P; }; } export interface UseApiProps

extends LoadingState { trigger: (p: P) => void; action: ActionFn

; } export interface UseApiSimpleProps extends LoadingState { trigger: () => void; action: ActionFn; } export interface UseApiAction extends LoadingState { trigger: () => void; action: A; } export declare type UseApiResult = UseApiProps

| UseApiSimpleProps | UseApiAction; interface UseCacheResult extends UseApiAction { data: D | null; } /** * useLoader will take an action creator or action itself and return the associated * loader for it. * * @returns the loader object for an action creator or action * * @example * ```ts * import { useLoader } from 'saga-query/react'; * * import { api } from './api'; * * const fetchUsers = api.get('/users', function*() { * // ... * }); * * const View = () => { * const loader = useLoader(fetchUsers); * // or: const loader = useLoader(fetchUsers()); * return

{loader.isLoader ? 'Loading ...' : 'Done!'}
* } * ``` */ export declare function useLoader(action: SagaAction | ActionFn): LoadingState>; /** * useApi will take an action creator or action itself and fetch * the associated loader and create a `trigger` function that you can call * later in your react component. * * This hook will *not* fetch the data for you because it does not know how to fetch * data from your redux state. * * @example * ```ts * import { useApi } from 'saga-query/react'; * * import { api } from './api'; * * const fetchUsers = api.get('/users', function*() { * // ... * }); * * const View = () => { * const { isLoading, trigger } = useApi(fetchUsers); * useEffect(() => { * trigger(); * }, []); * return
{isLoading ? : 'Loading' : 'Done!'}
* } * ``` */ export declare function useApi

>(action: A): UseApiAction; export declare function useApi

>(action: ActionFn

): UseApiProps

; export declare function useApi(action: ActionFnSimple): UseApiSimpleProps; /** * useQuery uses {@link useApi} and automatically calls `useApi().trigger()` * * @example * ```ts * import { useQuery } from 'saga-query/react'; * * import { api } from './api'; * * const fetchUsers = api.get('/users', function*() { * // ... * }); * * const View = () => { * const { isLoading } = useQuery(fetchUsers); * return

{isLoading ? : 'Loading' : 'Done!'}
* } * ``` */ export declare function useQuery

>(action: A): UseApiAction; /** * useCache uses {@link useQuery} and automatically selects the cached data associated * with the action creator or action provided. * * @example * ```ts * import { useCache } from 'saga-query/react'; * * import { api } from './api'; * * const fetchUsers = api.get('/users', api.cache()); * * const View = () => { * const { isLoading, data } = useCache(fetchUsers()); * return

{isLoading ? : 'Loading' : data.length}
* } * ``` */ export declare function useCache(action: A): UseCacheResult; /** * useLoaderSuccess will activate the callback provided when the loader transitions * from some state to success. * * @example * ```ts * import { useLoaderSuccess, useApi } from 'saga-query/react'; * * import { api } from './api'; * * const createUser = api.post('/users', function*(ctx, next) { * // ... * }); * * const View = () => { * const { loader, trigger } = useApi(createUser); * const onSubmit = () => { * trigger({ name: 'bob' }); * }; * * useLoaderSuccess(loader, () => { * // success! * // Use this callback to navigate to another view * }); * * return * } * ``` */ export declare function useLoaderSuccess(cur: Pick, success: () => any): void; export {};