UNPKG

@simonkov/use-axios

Version:

A custom React hook that provides a state-driven interface for Axios requests.

29 lines 1.26 kB
import { AxiosError, type AxiosInstance, type AxiosRequestConfig, type AxiosResponse } from "axios"; export type UseAxiosIndicators = { isFinished: boolean; isAborted: boolean; isLoading: boolean; isPending: boolean; isSuccess: boolean; isError: boolean; isConcurrencyFailure: boolean; }; export type UseAxiosState<T = any, C = any, R = AxiosResponse<T>> = { response: R | null; error: AxiosError<C> | null; } & UseAxiosIndicators; export type UseAxiosReturn<T = any, C = any, R = AxiosResponse<T>, D = any> = [ ((data?: AxiosRequestConfig<D>) => Promise<R>), UseAxiosState<T, C, R> ]; export type UseAxiosOptions<T = any, R = AxiosResponse<T>> = { instance?: AxiosInstance; immediate?: boolean; intercept?: (value: Promise<R>) => Promise<R>; preventConcurrent?: boolean; }; export declare function useAxios<T = any, C = any, R = AxiosResponse<T>, D = any>(requestConfig: AxiosRequestConfig<D>, options?: { immediate: true; } & UseAxiosOptions<T, R>): UseAxiosState<T, C, R>; export declare function useAxios<T = any, C = any, R = AxiosResponse<T>, D = any>(requestConfig: AxiosRequestConfig<D>, options?: UseAxiosOptions<T, R>): UseAxiosReturn<T, C, R, D>; //# sourceMappingURL=main.d.ts.map