Skip to content

v4.0.0: Hooks as first-class citizen

Compare
Choose a tag to compare
@ghengeveld ghengeveld released this 13 Feb 10:12
· 616 commits to master since this release

React Async

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 an args array as the first argument, instead of arguments to run 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 the options object as optional second argument. This used to be initialValue, but was undocumented and inflexible.