UNPKG

use-fetch-url

Version:

A custom hooks in TypeScript for fetching data from a URL and managing its state, including status and error information.

21 lines (20 loc) 648 B
import { FetchStatus } from "./constants"; type CompleteFetch<T> = { status: FetchStatus.COMPLETE; data: T; error: null; }; type LoadingFetch = { status: FetchStatus.LOADING; data: null; error: null; }; type ErrorFetch<T> = { status: FetchStatus.ERROR; data: null; error: T; }; type AnswerFetch<T, K> = CompleteFetch<T> | LoadingFetch | ErrorFetch<K>; export declare function useFetch<T, K = unknown>(fetch: () => Promise<T>, initialValue?: T | null): AnswerFetch<T, K>; export declare function useFetchUrl<T, K = unknown>(url: string, initialValue?: T | null): AnswerFetch<T, K>; export {};