Skip to content

Commit 2f2e572

Browse files
committed
alternate solution: set lastOptions.current on watchfn
1 parent 17e2d54 commit 2f2e572

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/react-async/src/useAsync.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ const useAsync = (arg1, arg2) => {
9797
.then(handleResolve(counter.current))
9898
.catch(handleReject(counter.current))
9999
} else if (promiseFn && !isPreInitialized) {
100-
start(() => promiseFn(options, abortController.current))
100+
start(() => promiseFn(lastOptions.current, abortController.current))
101101
.then(handleResolve(counter.current))
102102
.catch(handleReject(counter.current))
103103
}
104-
}, [initialValue, promise, promiseFn, start, handleResolve, handleReject, options])
104+
}, [start, promise, promiseFn, initialValue, handleResolve, handleReject])
105105

106106
const { deferFn } = options
107107
const run = useCallback(
@@ -132,7 +132,10 @@ const useAsync = (arg1, arg2) => {
132132
/* eslint-disable react-hooks/exhaustive-deps */
133133
const { watch, watchFn } = options
134134
useEffect(() => {
135-
if (watchFn && lastOptions.current && watchFn(options, lastOptions.current)) load()
135+
if (watchFn && lastOptions.current && watchFn(options, lastOptions.current)) {
136+
lastOptions.current = options
137+
load()
138+
}
136139
})
137140
useEffect(() => {
138141
lastOptions.current = options

0 commit comments

Comments
 (0)