@react-pakistan/util-functions 1.23.90 → 1.23.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hooks/use-fetch.d.ts +4 -5
- package/hooks/use-fetch.js +16 -2
- package/package.json +1 -1
package/hooks/use-fetch.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
interface FetchResult {
|
|
1
|
+
export interface FetchResult {
|
|
2
2
|
data: any;
|
|
3
3
|
error: any;
|
|
4
4
|
}
|
|
5
|
-
interface FetchConfig extends RequestInit {
|
|
5
|
+
export interface FetchConfig extends RequestInit {
|
|
6
6
|
autoFetch?: boolean;
|
|
7
7
|
callback?: (result: FetchResult) => void;
|
|
8
8
|
}
|
|
9
|
-
interface Return {
|
|
9
|
+
export interface Return {
|
|
10
10
|
apiResult: API_RESULT | undefined;
|
|
11
11
|
data: any;
|
|
12
12
|
error: any;
|
|
@@ -17,5 +17,4 @@ export declare enum API_RESULT {
|
|
|
17
17
|
SUCCESS = "SUCCESS",
|
|
18
18
|
ERROR = "ERROR"
|
|
19
19
|
}
|
|
20
|
-
export declare const useFetch: (url: string, config?: FetchConfig) => Return;
|
|
21
|
-
export {};
|
|
20
|
+
export declare const useFetch: (url: string, config?: FetchConfig, deps?: Array<string> | Array<any>) => Return;
|
package/hooks/use-fetch.js
CHANGED
|
@@ -58,6 +58,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
58
58
|
}
|
|
59
59
|
return t;
|
|
60
60
|
};
|
|
61
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
62
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
63
|
+
if (ar || !(i in from)) {
|
|
64
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
65
|
+
ar[i] = from[i];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
69
|
+
};
|
|
61
70
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
71
|
exports.useFetch = exports.API_RESULT = void 0;
|
|
63
72
|
var react_1 = require("react");
|
|
@@ -66,8 +75,9 @@ var API_RESULT;
|
|
|
66
75
|
API_RESULT["SUCCESS"] = "SUCCESS";
|
|
67
76
|
API_RESULT["ERROR"] = "ERROR";
|
|
68
77
|
})(API_RESULT || (exports.API_RESULT = API_RESULT = {}));
|
|
69
|
-
var useFetch = function (url, config) {
|
|
78
|
+
var useFetch = function (url, config, deps) {
|
|
70
79
|
if (config === void 0) { config = {}; }
|
|
80
|
+
if (deps === void 0) { deps = []; }
|
|
71
81
|
var callback = config.callback, _a = config.autoFetch, autoFetch = _a === void 0 ? false : _a, defaultOptions = __rest(config, ["callback", "autoFetch"]);
|
|
72
82
|
var _b = (0, react_1.useState)(null), data = _b[0], setData = _b[1];
|
|
73
83
|
var _c = (0, react_1.useState)(null), error = _c[0], setError = _c[1];
|
|
@@ -132,7 +142,11 @@ var useFetch = function (url, config) {
|
|
|
132
142
|
case 6: return [2 /*return*/];
|
|
133
143
|
}
|
|
134
144
|
});
|
|
135
|
-
}); }, [
|
|
145
|
+
}); }, __spreadArray([
|
|
146
|
+
url,
|
|
147
|
+
defaultOptions,
|
|
148
|
+
callback
|
|
149
|
+
], deps, true));
|
|
136
150
|
(0, react_1.useEffect)(function () {
|
|
137
151
|
if (autoFetch) {
|
|
138
152
|
fetchNow();
|