UNPKG

@anb98/react-hooks

Version:
48 lines 1.9 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); var useLazyFetchCache_1 = require("./useLazyFetchCache"); /** * 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 */ var useFetchCache = function (url, props) { var _a = (props || {}).deps, deps = _a === void 0 ? [] : _a; return (0, useLazyFetchCache_1.default)(__assign(__assign({}, props), { url: url, deps: __spreadArray(__spreadArray([], deps, true), [url], false) })); }; exports.default = useFetchCache; //# sourceMappingURL=useFetchCache.js.map