useFetch
This hooks aims to retrieve data from server.
import { useFetch } from "@hyper-fetch/react"
Parameters
useFetch<R>(request: R, options: UseFetchOptionsType<R>)
| Name | Type | Description |
|---|---|---|
| request | | Request instance |
| options | | Hook options |
Returns
type UseFetchReturnType<R> = UseTrackedStateType<R> & UseTrackedStateActions<R> & UseRequestEventsActionsType<R> & { bounce: { active: boolean; reset: () => void }; refetch: () => void };
| Name | Type | Description |
|---|---|---|
| data | | Request response data |
| error | | Request response error |
| extra | | Request additional response data |
| loading | | Request loading state |
| requestTimestamp | | Request response timestamp |
| responseTimestamp | | Request response timestamp |
| retries | | Request attempts |
| status | | Request status |
| success | | Information whether request succeeded |
| bounce | | Data related to current state of the bounce usage |
| setData | | Action to set custom data. We can do it locally(inside hook state). If you need to update cache data use client.cache.update(). method. |
| setError | | Action to set custom error. We can do it locally(inside hook state). If you need to update cache data use client.cache.update() method. |
| setExtra | | Action to set custom additional data. We can do it locally(inside hook state). If you need to update cache data use client.cache.update() method. |
| setLoading | | Action to set custom loading. We can do it locally(inside hook state). If you need to update cache data use client.cache.update() method. |
| setRequestTimestamp | | Action to set custom timestamp. We can do it locally(inside hook state). If you need to update cache data use client.cache.update() method. |
| setResponseTimestamp | | Action to set custom timestamp. We can do it locally(inside hook state). If you need to update cache data use client.cache.update() method. |
| setRetries | | Action to set custom retries count. We can do it locally(inside hook state). If you need to update cache data use client.cache.update() method. |
| setStatus | | Action to set custom status. We can do it locally(inside hook state). If you need to turn on loading for all listening hooks use client.requestManager.events.emitLoading() method. |
| setSuccess | | Action to set custom success. We can do it locally(inside hook state). If you need to update cache data use client.cache.update() method. |
| abort | | Callback that allows canceling ongoing requests from the given queryKey. |
| onAbort | | Helper hook listening on aborting of requests. Abort events are not triggering onError callbacks. |
| onDownloadProgress | | Helper hook listening on download progress ETA. We can later match given requests by their id's or request instance which holds all data which is being transferred. |
| onError | | Helper hook listening on error response. |
| onFinished | | Helper hook listening on any response. |
| onOfflineError | | Helper hook listening on request going into offline awaiting for network connection to be restored. It will not trigger onError when 'offline' mode is set on request. |
| onRequestStart | | Helper hook listening on request start. |
| onResponseStart | | Helper hook listening on response start(before we receive all data from server). |
| onSuccess | | Helper hook listening on success response. |
| onUploadProgress | | Helper hook listening on upload progress ETA. We can later match given requests by their id's or request instance which holds all data which is being transferred. |
| refetch | | Refetch current request |