@lemon-fe/hooks 0.1.140 → 0.1.142
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
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lemon-fe/hooks",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.142",
|
|
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": "99cc7a85d28b2380ee970ff1f616fe1f77b44259"
|
|
28
|
+
}
|
|
30
29
|
}
|