@lemon-fe/hooks 0.1.139 → 0.1.141
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/es/useRequest/index.d.ts +1 -0
- package/es/useRequest/index.js +12 -3
- package/package.json +2 -3
package/es/useRequest/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* @param loadingState 启用loading状态
|
|
10
10
|
*/
|
|
11
11
|
export default function useRequest<T extends (...args: any[]) => PromiseLike<any>, K = T extends (...args: any) => PromiseLike<infer U> | infer U ? U : never>(request: T, options?: {
|
|
12
|
+
onLoading?: (loading?: boolean) => void;
|
|
12
13
|
onSuccess?: (res: K) => void;
|
|
13
14
|
onError?: (err: Error) => void;
|
|
14
15
|
throttleInterval?: number;
|
package/es/useRequest/index.js
CHANGED
|
@@ -31,7 +31,8 @@ export default function useRequest(request) {
|
|
|
31
31
|
_options$debounceInte = options.debounceInterval,
|
|
32
32
|
debounceInterval = _options$debounceInte === void 0 ? 0 : _options$debounceInte,
|
|
33
33
|
loadingState = options.loadingState,
|
|
34
|
-
toast = options.toast
|
|
34
|
+
toast = options.toast,
|
|
35
|
+
onLoading = options.onLoading;
|
|
35
36
|
var _useState = useState(false),
|
|
36
37
|
_useState2 = _slicedToArray(_useState, 2),
|
|
37
38
|
loading = _useState2[0],
|
|
@@ -46,6 +47,9 @@ export default function useRequest(request) {
|
|
|
46
47
|
if (loadingState) {
|
|
47
48
|
setLoading(true);
|
|
48
49
|
}
|
|
50
|
+
if (onLoading) {
|
|
51
|
+
onLoading(true);
|
|
52
|
+
}
|
|
49
53
|
};
|
|
50
54
|
var end = function end() {
|
|
51
55
|
if (toastRef.current) {
|
|
@@ -58,6 +62,9 @@ export default function useRequest(request) {
|
|
|
58
62
|
if (loadingState) {
|
|
59
63
|
setLoading(false);
|
|
60
64
|
}
|
|
65
|
+
if (onLoading) {
|
|
66
|
+
onLoading(false);
|
|
67
|
+
}
|
|
61
68
|
};
|
|
62
69
|
useEffect(function () {
|
|
63
70
|
mounted.current = true;
|
|
@@ -96,13 +103,15 @@ export default function useRequest(request) {
|
|
|
96
103
|
hooksOpts.showError(_context.t0);
|
|
97
104
|
}
|
|
98
105
|
case 14:
|
|
106
|
+
_context.prev = 14;
|
|
99
107
|
end();
|
|
100
|
-
|
|
108
|
+
return _context.finish(14);
|
|
109
|
+
case 17:
|
|
101
110
|
case "end":
|
|
102
111
|
return _context.stop();
|
|
103
112
|
}
|
|
104
113
|
}
|
|
105
|
-
}, _callee, null, [[3, 11]]);
|
|
114
|
+
}, _callee, null, [[3, 11, 14, 17]]);
|
|
106
115
|
}));
|
|
107
116
|
return function run() {
|
|
108
117
|
return _ref.apply(this, arguments);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lemon-fe/hooks",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.141",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "鲁盛杰 <lusj@cnlemon.net>",
|
|
6
6
|
"homepage": "",
|
|
@@ -25,6 +25,5 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/color-string": "^1.5.2",
|
|
27
27
|
"react": "^17.0.2"
|
|
28
|
-
}
|
|
29
|
-
"gitHead": "0ec818be2c117d27f3a12ef68ee4d41849b73746"
|
|
28
|
+
}
|
|
30
29
|
}
|