react-fetch-component icon indicating copy to clipboard operation
react-fetch-component copied to clipboard

Add support for Hooks

Open techniq opened this issue 5 years ago • 1 comments

Support useFetch hooks API

function Example(props) {
  const { loading, data, error } = useFetch({ url: props.url });
  // ...
}

along with the existing Fetch render props component

function Example(props) {
  <Fetch url={props.url}>
    {({ loading, data, error }) => (
      // ...
    )}
  </Fetch>
}

To support consistency with the Fetch component, the useFetch hook will take in a props object for url, options, etc.

I might consider change the name of the package to better represent it's not just a component (but also a hook). I'm considering using a scoped @techniq/react-fetch instead of trying to come up with a unique name.

TODO

  • [ ] Update README
  • [ ] Switch to Typescript
  • [ ] Wait for official React release with hooks

techniq avatar Dec 06 '18 00:12 techniq

Released as npm install react-fetch-component@next (pre-release 8.0.0-0).

Package name may change before becoming official (and won't be official until Hooks are official / non-alpha)

techniq avatar Dec 06 '18 00:12 techniq