@anb98/react-hooks
Version:
Custom hooks for react
34 lines (33 loc) • 1.26 kB
TypeScript
import { UseLazyFetchProps, RequestUseLazyFetch } from './useLazyFetch';
declare type Refresh = {
refresh?: boolean;
};
declare type VerifyCache = (request?: RequestUseLazyFetch, options?: Refresh) => void;
/**
* 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 ] = useLazyFetchCache({
url: 'your-endpoint-url',
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 useLazyFetchCache: <T = any>(props?: Partial<UseLazyFetchProps<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";
}, VerifyCache, () => void, () => void];
export default useLazyFetchCache;