UseFetch
katanakit-js / useFetch
Function: useFetch()
Section titled “Function: 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 Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
T |
unknown |
Parameters
Section titled “Parameters”| 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. |
Returns
Section titled “Returns”Promise<FetchResult<T>>
A FetchResult with data or error. Never throws.
Example
Section titled “Example”import { useFetch } from "katanakit-js";
const result = await useFetch("pokeapi", "pokemonById", { params: { id: 25 } });if (result.ok) console.log(result.data);