Skip to content

v8.0.0: Renamed helpers, new promise prop, modify useFetch's init

Compare
Choose a tag to compare
@ghengeveld ghengeveld released this 23 Aug 21:16
· 421 commits to master since this release

React Async

  • Resolved an issue with ambiguous imports, where helpers such as Fulfilled clash with React.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 as run, cancel and reload (hooks only) (#82)
  • Allow modification of useFetch's init param from run (#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)