@@ -11,7 +11,7 @@ const useAsync = (arg1, arg2) => {
1111 const counter = useRef ( 0 )
1212 const isMounted = useRef ( true )
1313 const lastArgs = useRef ( undefined )
14- const prevOptions = useRef ( undefined )
14+ const lastOptions = useRef ( undefined )
1515 const abortController = useRef ( { abort : noop } )
1616
1717 const { devToolsDispatcher } = globalScope . __REACT_ASYNC__
@@ -72,7 +72,7 @@ const useAsync = (arg1, arg2) => {
7272 }
7373 const isPreInitialized = initialValue && counter . current === 0
7474 if ( promiseFn && ! isPreInitialized ) {
75- return start ( ( ) => promiseFn ( options , abortController . current ) ) . then (
75+ return start ( ( ) => promiseFn ( lastOptions . current , abortController . current ) ) . then (
7676 handleResolve ( counter . current ) ,
7777 handleReject ( counter . current )
7878 )
@@ -83,7 +83,7 @@ const useAsync = (arg1, arg2) => {
8383 const run = ( ...args ) => {
8484 if ( deferFn ) {
8585 lastArgs . current = args
86- return start ( ( ) => deferFn ( args , options , abortController . current ) ) . then (
86+ return start ( ( ) => deferFn ( args , lastOptions . current , abortController . current ) ) . then (
8787 handleResolve ( counter . current ) ,
8888 handleReject ( counter . current )
8989 )
@@ -99,15 +99,15 @@ const useAsync = (arg1, arg2) => {
9999
100100 const { watch, watchFn } = options
101101 useEffect ( ( ) => {
102- if ( watchFn && prevOptions . current && watchFn ( options , prevOptions . current ) ) load ( )
102+ if ( watchFn && lastOptions . current && watchFn ( options , lastOptions . current ) ) load ( )
103103 } )
104+ useEffect ( ( ) => ( lastOptions . current = options ) && undefined )
104105 useEffect ( ( ) => {
105106 if ( counter . current ) cancel ( )
106107 if ( promise || promiseFn ) load ( )
107108 } , [ promise , promiseFn , watch ] )
108109 useEffect ( ( ) => ( ) => ( isMounted . current = false ) , [ ] )
109110 useEffect ( ( ) => ( ) => cancel ( ) , [ ] )
110- useEffect ( ( ) => ( prevOptions . current = options ) && undefined )
111111
112112 useDebugValue ( state , ( { status } ) => `[${ counter . current } ] ${ status } ` )
113113
0 commit comments