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:
deferFnnow receives anargsarray as the first argument, instead of arguments torunbeing 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
useAsyncnow takes theoptionsobject as optional second argument. This used to beinitialValue, but was undocumented and inflexible.
