UNPKG

create-fetch-hooks

Version:

A simple and powerful custom React hook (useApi) that simplifies API requests with automatic loading and error states. Ideal for clean and maintainable data fetching in React components.

21 lines (20 loc) 889 B
import { FetchError } from "./types/FetchError"; export type PostOptions<ResponseType> = { onSuccess?: (res: ResponseType) => void; onError?: (error: FetchError) => void; onResponseGot?: (url: string, endpoint: string, responseCode: number | string | undefined) => void; convertToFormData?: boolean; removeIfValueIsNullOrUndefined?: boolean; headers?: Record<string, string>; signal?: AbortSignal | null | undefined; accessTokenLocalStorageKey?: string; callRefreshToken?: () => { on: number[]; body: Record<string, string>; endpoint: string; saveAccessTokenFromResponse?: (res: any) => void; }; retryCount?: number; retryDelay?: number; }; export declare function post<PostDataType, ResponseType>(baseApiUrl: string, url: string, dataToPost: PostDataType, options?: PostOptions<ResponseType>): Promise<any>;