import type { ApiError, UrlOptions } from "../../types/index.js"; /** Reactive state exposed by the {@link useRequest} hook. */ export interface RequestState { /** The resolved data on success, `null` otherwise. */ data: T | null; /** The Safe Result error on failure, `null` otherwise. */ error: ApiError | null; /** Whether a request is in flight. */ loading: boolean; /** Re-runs the request manually. */ refetch: () => Promise; } /** * React hook that wraps KatanaKit's HTTP GET with `useState` reactivity. * Bridges the Safe Result pattern to idiomatic React state and never throws * on HTTP errors. * * Stale responses are ignored via a request version counter and AbortController; * in-flight requests are aborted on unmount. Re-fetches automatically when the * serialized `options` change. * * @param apiName - Name of the registered API (see `useInitApis`). * @param endpointName - Name of the endpoint inside that API. * @param options - Optional `UrlOptions` (path/query params). * @returns `{ data, error, loading, refetch }`. * * @example * ```tsx * import { useRequest } from "katanakit-js/adapters/react"; * * function Pokemon({ id }: { id: number }) { * const { data, error, loading } = useRequest<{ name: string }>( * "pokeapi", * "pokemonById", * { params: { id } }, * ); * if (loading) return
Loading…
; * if (error) return
{error.message}
; * return
{data?.name}
; * } * ``` */ export declare function useRequest(apiName: string, endpointName: string, options?: UrlOptions): RequestState; //# sourceMappingURL=fetch.d.ts.map