v8.0.0: Renamed helpers, new promise prop, modify useFetch's init
React Async
- Resolved an issue with ambiguous imports, where helpers such as
Fulfilled
clash withReact.Fulfilled
(#73) - Added
promise
render prop to allow chaining on it (#83) - Better TypeScript definitions for helper components (#72)
- Applied
useCallback
to the returned functions such asrun
,cancel
andreload
(hooks only) (#82) - Allow modification of
useFetch
'sinit
param fromrun
(#76 by @phryneas) - Improved TypeScript types for
promiseFn
/deferFn
props - Introduced codemods for automatic upgrades
- Aligned version numbers for all packages and examples
Breaking change: renamed helpers
All stand-alone helper components are renamed without backwards compatibility. Child components of <Async>
are unaffected. To upgrade:
- replace
<Initial>
with<IfInitial>
- replace
<Pending>
with<IfPending>
- replace
<Fulfilled>
with<IfFulfilled>
- replace
<Rejected>
with<IfRejected>
- replace
<Settled>
with<IfSettled>
Note this does not apply to <Async.Initial>
and the like.
A codemod is available to automate the upgrade.
Breaking change: run
return type
The return type for run
was changed from Promise
to undefined
. You should now use the promise
prop instead. This is a manual upgrade. For example:
- const { run } = useAsync(...)
+ const { run, promise } = useAsync(...)
+ useEffect(() => {
+ promise.then(onData, onError)
+ }, [promise])
- const handleClick = () => run(arg).then(onData, onError)
+ const handleClick = () => run(arg)