{name}
{image_url && (
src={image_url}
alt={name}
/>
)}
Fetch hook implementation with abort
Fetch hook implementation with abort
```
npm install --save @hmn/use-fetch
`javascript`
import useFetch from '@hmn/use-fetch'
`jsx
const Demo = () => {
const { result = [] } = useFetch('https://api.punkapi.com/v2/beers/random')
const beer = result[0]
if (beer) {
const { name, image_url } = beer
return (
{name}
{image_url && (
style={{ height: 200, margin: 20 }}
src={image_url}
alt={name}
/>
)}
)
}
return null
}
`
#### Pending state, error, run method (for refetching data)
`jsx
const DemoAdvanced = () => {
const { pending, error, result = [], run } = useFetch('https://api.punkapi.com/v2/beers/random')
if (pending) {
return
}
if (error) {
return
const beer = result[0]
if (beer) {
const { name, abv, ibu, description, image_url } = beer
return ( {description}
{name}
{image_url && (
style={{ height: 200, margin: 20 }}
src={image_url}
alt={name}
/>
)}
)
}
}
render(
``