useFetch
🐶 A React hook for making http requests
Need to fetch some data? Try this one out.
Examples
Installation
yarn add use-http
Usage
Stateless
import useFetch from 'use-http'
function App() {
const [data, loading, error] = useFetch('https://example.com')
if (error) {
return 'Error!'
}
if (loading) {
return 'Loading!'
}
return (
<code>
<pre>{data}</pre>
</code>
)
}
Options
Option | Description |
---|
options | This is exactly what you would pass to the normal js fetch |
Option Usage
const options = {
method: 'POST'
}
const [data, loading, error] = useFetch(url, options)