# use-fetch-react

> Using fetch in a react hook.

Latest version **0.0.3** (published 2019-10-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-fetch-react
pnpm add use-fetch-react
yarn add use-fetch-react
bun add use-fetch-react
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2019-10-27 |
| First published | 2019-10-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | CalebBarnes |
| Maintainers | calebbarnes |

## Links

- npm: https://www.npmjs.com/package/use-fetch-react
- npm.io page: https://npm.io/package/use-fetch-react

## Recent versions

- 0.0.3 (latest) — 2019-10-27
- 0.0.2 — 2019-10-27
- 0.0.1 — 2019-10-27

## README

# use-fetch-react

### Usage

`import { useFetch } from "use-fetch-react"`
```
const Page = () => {
  const [request, { data, error, loading, called }] = useFetch(
    "https://swapi.co/api/people",
    {
      onCompleted(response) {
        console.log("onCompleted", response)
      },
      onError(err) {
        console.log("onError", err)
      },
    }
  )

  return (
    <>
      {!called && <p>Please press the fetch button</p>}
      {error && <ErrorMessage>{error.message}</ErrorMessage>}

      <Button
        loading={loading}
        onClick={request}
      >
        Request
      </Button>
      
      {loading && (
        <div>
          <BarLoader />
        </div>
      )}

      {data &&
        data.results &&
        data.results.map((person, index) => {
          return <div key={index}>{person.name}</div>
        })}
    </>
  )
}
```

---
_Source: https://npm.io/package/use-fetch-react · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
