useCache
import { useCache } from "@hyper-fetch/react"
Parameters
useCache<T>(request: T, options: UseCacheOptionsType<T>)
| Name | Type | Description |
|---|---|---|
| request | | |
| options | |
Returns
type UseCacheReturnType<T> = UseTrackedStateType<T> & UseTrackedStateActions<T> & { invalidate: (cacheKeys?: string | RegExp | RequestInstance | (string | RegExp | RequestInstance)[]) => 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 |
| 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. |
| invalidate | | Invalidate cache for the current request or pass custom key to trigger it by invalidationKey(Regex / cacheKey). |