Skip to content

UseFetch

katanakit-js / useFetch

function useFetch<T>(
apiName,
endpointName,
options?
): Promise<FetchResult<T>>;

Defined in: core/services/http.service.ts:647

Fetches a registered endpoint and returns a Safe Result.

Type Parameter Default type
T unknown
Parameter Type Description
apiName string The registered API key.
endpointName string The endpoint key within the API.
options? FetchOptions<T> Fetch options: params, query, transform and any RequestInit field.

Promise<FetchResult<T>>

A FetchResult with data or error. Never throws.

import { useFetch } from "katanakit-js";
const result = await useFetch("pokeapi", "pokemonById", { params: { id: 25 } });
if (result.ok) console.log(result.data);