Skip to content
0

katanakit-js / useFetch

Function: useFetch() ​

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

Defined in: src/core/services/http.service.ts:704

Fetches a registered endpoint and returns a Safe Result.

Type Parameters ​

Type ParameterDefault type
Tunknown

Parameters ​

ParameterTypeDescription
apiNamestringThe registered API key.
endpointNamestringThe endpoint key within the API.
optionsFetchOptions<T>Fetch options: params, query, transform and any RequestInit field.

Returns ​

Promise<FetchResult<T>>

A FetchResult with data or error. Never throws.

Example ​

ts
import { useFetch } from "katanakit-js";

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

Released under the MIT License.