@supunlakmal/hooks
Version:
A collection of reusable React hooks
18 lines (17 loc) • 702 B
TypeScript
interface FetchOptions extends RequestInit {
}
/**
* Custom hook for fetching data from an API endpoint.
*
* @template T The expected type of the data to be fetched.
* @param {string | null | undefined} url The URL to fetch data from. If null or undefined, the fetch is not executed.
* @param {FetchOptions} [options] Optional fetch options (e.g., method, headers, body).
* @returns {FetchState<T>} An object containing the fetched data, loading state, and error state.
*/
export interface FetchState<T> {
data: T | null;
loading: boolean;
error: Error | null;
}
export declare const useFetch: <T>(url: string | null | undefined, options?: FetchOptions) => FetchState<T>;
export {};