@@ -11,7 +11,7 @@ const useAsync = (arg1, arg2) => {
11
11
const counter = useRef ( 0 )
12
12
const isMounted = useRef ( true )
13
13
const lastArgs = useRef ( undefined )
14
- const prevOptions = useRef ( undefined )
14
+ const lastOptions = useRef ( undefined )
15
15
const abortController = useRef ( { abort : noop } )
16
16
17
17
const { devToolsDispatcher } = globalScope . __REACT_ASYNC__
@@ -72,7 +72,7 @@ const useAsync = (arg1, arg2) => {
72
72
}
73
73
const isPreInitialized = initialValue && counter . current === 0
74
74
if ( promiseFn && ! isPreInitialized ) {
75
- return start ( ( ) => promiseFn ( options , abortController . current ) ) . then (
75
+ return start ( ( ) => promiseFn ( lastOptions . current , abortController . current ) ) . then (
76
76
handleResolve ( counter . current ) ,
77
77
handleReject ( counter . current )
78
78
)
@@ -83,7 +83,7 @@ const useAsync = (arg1, arg2) => {
83
83
const run = ( ...args ) => {
84
84
if ( deferFn ) {
85
85
lastArgs . current = args
86
- return start ( ( ) => deferFn ( args , options , abortController . current ) ) . then (
86
+ return start ( ( ) => deferFn ( args , lastOptions . current , abortController . current ) ) . then (
87
87
handleResolve ( counter . current ) ,
88
88
handleReject ( counter . current )
89
89
)
@@ -99,15 +99,15 @@ const useAsync = (arg1, arg2) => {
99
99
100
100
const { watch, watchFn } = options
101
101
useEffect ( ( ) => {
102
- if ( watchFn && prevOptions . current && watchFn ( options , prevOptions . current ) ) load ( )
102
+ if ( watchFn && lastOptions . current && watchFn ( options , lastOptions . current ) ) load ( )
103
103
} )
104
+ useEffect ( ( ) => ( lastOptions . current = options ) && undefined )
104
105
useEffect ( ( ) => {
105
106
if ( counter . current ) cancel ( )
106
107
if ( promise || promiseFn ) load ( )
107
108
} , [ promise , promiseFn , watch ] )
108
109
useEffect ( ( ) => ( ) => ( isMounted . current = false ) , [ ] )
109
110
useEffect ( ( ) => ( ) => cancel ( ) , [ ] )
110
- useEffect ( ( ) => ( prevOptions . current = options ) && undefined )
111
111
112
112
useDebugValue ( state , ( { status } ) => `[${ counter . current } ] ${ status } ` )
113
113
0 commit comments