Releases: async-library/react-async
v4.1.0: PropTypes and debugValue
- Adds optional PropTypes support, based on whether
prop-types
is installed (prop-types
is an optional dependency). - Adds a debug value to
useAsync
anduseFetch
for React DevTools.
v4.0.0: Hooks as first-class citizen
This is a major update making useAsync
the primary interface, stabilizing its API. It also adds the useFetch
hook for more convenience working with HTTP requests.
import { useFetch } from "react-async"
const MyComponent = () => {
const headers = { Accept: "application/json" }
const { data, error, isLoading } = useFetch("/api/example", { headers })
// This will setup a promiseFn with a fetch request and JSON deserialization.
}
Furthermore there's several breaking changes:
deferFn
now receives anargs
array as the first argument, instead of arguments torun
being spread at the front of the arguments list. This enables better interop with TypeScript. You can use destructuring to keep using your existing variables.- The shorthand version of
useAsync
now takes theoptions
object as optional second argument. This used to beinitialValue
, but was undocumented and inflexible.
v3.13.4: Fix onReject handler name in typings
- Fix
onReject
handler in typings.
v3.13.3: Fix "Uncaught TypeError: Illegal invocation" (#20)
- Fix #20: TypeError caused by calling
abortController.abort()
with invalid context.
v3.13.2: Deprecate undocumented useAsync shorthand
- Add deprecation notice for undocumented
useAsync(promiseFn, initialValue)
shorthand.
v3.13.1: Fix watchFn with default props
- Accepts
watchFn
from defaultProps when usingcreateInstance
. - Passes defaultProps to
watchFn
.
v3.13.0: Flexible automatic reloading with watchFn
- Add 'watchFn' for more flexibility in reloading based on prop changes.
- Fix AsyncProps type (#19)
v3.12.1: Fix passing defaultProps to deferFn
When using createInstance
with preconfigured props, deferFn now receives these defaultProps along with any other props.
v3.12.0: Abortable fetch using AbortController
React Async now automatically instantiates an AbortController with each promise. The controller is passed to the promiseFn
and/or deferFn
. Its signal
property can be passed as an option to fetch
. Whenever a promise is canceled, the signal is aborted, canceling the underlying HTTP request.
v3.11.0: useAsync
It's finally here: the useAsync
hook. This adds a very promising new way to use React Async, without the need for wrapper components. An important milestone.
useAsync
is a React hook that makes working with Promises a breeze. It provides metadata such as isLoading
and startedAt
and deals with race conditions and promise cancellation.
A working usage example is provided here: https://github.com/ghengeveld/react-async/tree/master/examples/basic-hook