techniq / react-fetch-component

React component and hook to declaratively fetch data
MIT License
158 stars 21 forks source link

Add support for Hooks #25

Open techniq opened 5 years ago

techniq commented 5 years ago

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

techniq commented 5 years ago

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)