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.
20 lines (19 loc) • 787 B
TypeScript
import { FetchError } from "./types/FetchError";
export type UseDeleteOptions<Response> = {
onSuccess?: (res: Response) => void;
onError?: (error: FetchError) => void;
onResponseGot?: (url: string, endpoint: string, responseCode: number | string | undefined) => void;
headers?: Record<string, string>;
accessTokenLocalStorageKey?: string;
callRefreshToken?: () => {
on: number[];
body: Record<string, string>;
endpoint: string;
saveAccessTokenFromResponse?: (res: any) => void;
};
};
export declare function useDelete<ResponseType>(baseApiUrl: string, url: string, options?: UseDeleteOptions<ResponseType>): {
error: FetchError | undefined;
loading: boolean;
deleteData: (id?: number | string) => Promise<void>;
};