File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -47,19 +47,22 @@ const useAsync = (opts, init) => {
47
47
const isPreInitialized = initialValue && counter . current === 0
48
48
if ( promiseFn && ! isPreInitialized ) {
49
49
start ( )
50
- promiseFn ( options ) . then ( handleResolve ( counter . current ) , handleReject ( counter . current ) )
50
+ return promiseFn ( options ) . then ( handleResolve ( counter . current ) , handleReject ( counter . current ) )
51
51
}
52
52
}
53
53
54
54
const run = ( ...args ) => {
55
55
if ( deferFn ) {
56
56
start ( )
57
57
lastArgs . current = args
58
- return deferFn ( ...args , options ) . then ( handleResolve ( counter . current ) , handleReject ( counter . current ) )
58
+ return deferFn ( ...args , options ) . then (
59
+ handleResolve ( counter . current ) ,
60
+ handleReject ( counter . current )
61
+ )
59
62
}
60
63
}
61
64
62
- useEffect ( load , [ promiseFn , watch ] )
65
+ useEffect ( ( ) => load ( ) && undefined , [ promiseFn , watch ] )
63
66
useEffect ( ( ) => ( ) => ( isMounted . current = false ) , [ ] )
64
67
65
68
return useMemo (
Original file line number Diff line number Diff line change @@ -83,7 +83,9 @@ describe("useAsync", () => {
83
83
test ( "passes reload function that re-runs the promise" , async ( ) => {
84
84
const promiseFn = jest . fn ( ) . mockReturnValue ( resolveTo ( "done" ) )
85
85
const component = (
86
- < Async promiseFn = { promiseFn } > { ( { reload } ) => < button onClick = { reload } > reload</ button > } </ Async >
86
+ < Async promiseFn = { promiseFn } >
87
+ { ( { reload } ) => < button onClick = { reload } > reload</ button > }
88
+ </ Async >
87
89
)
88
90
const { getByText } = render ( component )
89
91
flushEffects ( )
@@ -319,4 +321,4 @@ describe("useAsync", () => {
319
321
await waitForElement ( ( ) => getByText ( "outer undefined" ) )
320
322
await waitForElement ( ( ) => getByText ( "outer inner" ) )
321
323
} )
322
- } )
324
+ } )
You can’t perform that action at this time.
0 commit comments