This repository was archived by the owner on Aug 12, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
packages/console-utils/xconsole-service/src/hooks Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,11 @@ export interface ReturnValue<P, T> {
75
75
error ?: Error ;
76
76
data ?: T ;
77
77
cancel : noop ;
78
+ /**当次执行的 service 的参数数组*/
79
+ params ?: any [ ] ;
78
80
run : promiseReturn < P , T | undefined > ;
81
+ /**使用上一次的 params,重新调用 run */
82
+ refresh : ( ) => void ;
79
83
timer : {
80
84
stop : noop ;
81
85
resume : noop ;
@@ -92,6 +96,8 @@ export default function useAsync<P = any, Result = any>(
92
96
loading : false ,
93
97
cancel : noop ,
94
98
run : promiseReturn ,
99
+ params : [ ] ,
100
+ refresh :noop ,
95
101
timer : {
96
102
stop : noop ,
97
103
resume : promiseReturn ,
@@ -113,7 +119,7 @@ export default function useAsync<P = any, Result = any>(
113
119
const run = useCallback ( ( ...args : any [ ] ) : Promise < Result | undefined > => {
114
120
// 确保不会返回被取消的结果
115
121
const runCount = count . current ;
116
- set ( ( s ) => ( { ...s , loading : true } ) ) ;
122
+ set ( ( s ) => ( { ...s , loading : true , params : args } ) ) ;
117
123
return fn ( ...args )
118
124
. then ( ( data ) => {
119
125
if ( runCount === count . current ) {
@@ -139,6 +145,11 @@ export default function useAsync<P = any, Result = any>(
139
145
} ) ;
140
146
} , deps ) ;
141
147
148
+
149
+ const refresh = useCallback ( ( ) => {
150
+ run ( state . params || [ ] ) ;
151
+ } , [ ] ) ;
152
+
142
153
const stop = useCallback ( ( ) => {
143
154
count . current += 1 ;
144
155
// 清除计时器
@@ -248,7 +259,9 @@ export default function useAsync<P = any, Result = any>(
248
259
loading : state . loading ,
249
260
error : state . error ,
250
261
data : state . data ,
262
+ params :state . params ,
251
263
cancel,
264
+ refresh,
252
265
run : options . manual && options . pollingInterval ? start : reload ,
253
266
timer : {
254
267
stop,
You can’t perform that action at this time.
0 commit comments