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) => {
4747 const isPreInitialized = initialValue && counter . current === 0
4848 if ( promiseFn && ! isPreInitialized ) {
4949 start ( )
50- promiseFn ( options ) . then ( handleResolve ( counter . current ) , handleReject ( counter . current ) )
50+ return promiseFn ( options ) . then ( handleResolve ( counter . current ) , handleReject ( counter . current ) )
5151 }
5252 }
5353
5454 const run = ( ...args ) => {
5555 if ( deferFn ) {
5656 start ( )
5757 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+ )
5962 }
6063 }
6164
62- useEffect ( load , [ promiseFn , watch ] )
65+ useEffect ( ( ) => load ( ) && undefined , [ promiseFn , watch ] )
6366 useEffect ( ( ) => ( ) => ( isMounted . current = false ) , [ ] )
6467
6568 return useMemo (
Original file line number Diff line number Diff line change @@ -83,7 +83,9 @@ describe("useAsync", () => {
8383 test ( "passes reload function that re-runs the promise" , async ( ) => {
8484 const promiseFn = jest . fn ( ) . mockReturnValue ( resolveTo ( "done" ) )
8585 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 >
8789 )
8890 const { getByText } = render ( component )
8991 flushEffects ( )
@@ -319,4 +321,4 @@ describe("useAsync", () => {
319321 await waitForElement ( ( ) => getByText ( "outer undefined" ) )
320322 await waitForElement ( ( ) => getByText ( "outer inner" ) )
321323 } )
322- } )
324+ } )
You can’t perform that action at this time.
0 commit comments