Skip to content

Commit

Permalink
alternate solution: set lastOptions.current on watchfn
Browse files Browse the repository at this point in the history
  • Loading branch information
salolivares committed Nov 10, 2019
1 parent d5681a9 commit 85ca6a3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/react-async/src/useAsync.js
Expand Up @@ -97,11 +97,11 @@ const useAsync = (arg1, arg2) => {
.then(handleResolve(counter.current))
.catch(handleReject(counter.current))
} else if (promiseFn && !isPreInitialized) {
start(() => promiseFn(options, abortController.current))
start(() => promiseFn(lastOptions.current, abortController.current))
.then(handleResolve(counter.current))
.catch(handleReject(counter.current))
}
}, [initialValue, promise, promiseFn, start, handleResolve, handleReject, options])
}, [start, promise, promiseFn, initialValue, handleResolve, handleReject])

const { deferFn } = options
const run = useCallback(
Expand Down Expand Up @@ -132,7 +132,10 @@ const useAsync = (arg1, arg2) => {
/* eslint-disable react-hooks/exhaustive-deps */
const { watch, watchFn } = options
useEffect(() => {
if (watchFn && lastOptions.current && watchFn(options, lastOptions.current)) load()
if (watchFn && lastOptions.current && watchFn(options, lastOptions.current)) {
lastOptions.current = options
load()
}
})
useEffect(() => {
lastOptions.current = options
Expand Down

0 comments on commit 85ca6a3

Please sign in to comment.