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 Oct 31, 2019
1 parent 17e2d54 commit 2f2e572
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/react-async/src/useAsync.js
Original file line number Diff line number Diff line change
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 2f2e572

Please sign in to comment.