UNPKG

@anb98/react-hooks

Version:
32 lines (31 loc) 1.22 kB
import { UseFetchProps } from './useFetch'; /** * This hooks allow to cache results from request previously fetched. * To use this hooks you first need to implement CacheProvider. * @param {string} url URL to request * @param props Initial options * @example * ``` const [state, fetchHandler, resetState ] = useFetchCache('your-endpoint-url', { deps: [], initialData: {}, request: { headers: { example: 'test'} } onCancel: () => {}, onComplete: (data, err) => {}, onFail: (err) => {}, onSuccess: (data) => {}, }); * ``` * @see https://www.npmjs.com/package/@anb98/react-hooks#useFetchCache-and-useLazyFetchCache */ declare const useFetchCache: <T = any>(url: string, props?: Partial<UseFetchProps<T>> | undefined) => readonly [{ readonly data: T | undefined; readonly isSuccess: boolean; readonly isLoading: boolean; readonly isError: boolean; readonly error: any; readonly status: "idle" | "pending" | "resolved" | "rejected"; }, (request?: import("./useLazyFetch").RequestUseLazyFetch | undefined, options?: { refresh?: boolean | undefined; } | undefined) => void, () => void, () => void]; export default useFetchCache;