# react-custom-fetch-hook

> This is the custom react hook which you can use to call the api and it will return the data,error(if any),loading status.

Latest version **1.0.4** (published 2022-02-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-custom-fetch-hook
pnpm add react-custom-fetch-hook
yarn add react-custom-fetch-hook
bun add react-custom-fetch-hook
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2022-02-18 |
| First published | 2022-02-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | ATUL KUMAR SINGH |
| Maintainers | imrajput |
| Keywords | react, hooks, custom, fetch, api |

## Links

- npm: https://www.npmjs.com/package/react-custom-fetch-hook
- Repository: https://github.com/iamrajput/react-custom-hook
- Homepage: https://github.com/iamrajput/react-custom-hook#readme
- Issues: https://github.com/iamrajput/react-custom-hook/issues
- npm.io page: https://npm.io/package/react-custom-fetch-hook

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2022-02-18
- 1.0.3 — 2022-02-18
- 1.0.2 — 2022-02-18
- 1.0.1 — 2022-02-18
- 1.0.0 — 2022-02-18

## README

# react-custom-fetch-hook

[![GitHub issues](https://img.shields.io/github/issues/iamrajput/react-custom-hook)](https://circleci.com/gh/ilyalesik/react-fetch-hook)
[![npm version](https://img.shields.io/github/forks/iamrajput/react-custom-hook)](https://img.shields.io/github/forks/iamrajput/react-custom-hook)
[![GitHub stars](https://img.shields.io/github/stars/iamrajput/react-custom-hook)](https://img.shields.io/github/stars/iamrajput/react-custom-hook)

React hook for conveniently use Fetch API. It will take url and the extra header if needed.


```javascript

import useFetch from 'react-custom-fetch-hook'

function CustomHook() {
    const {data,loading} = useFetch('https://quotable.io/quotes',{})
  
    if(loading){
        return <h3>Loading...</h3>
    }
    return (
        <div>
            {data.results.map((result) => (
                   <p key={result._id}>{result.content}</p>
            ))}
        </div>
    )
}

```

*useFetch* accepts the same arguments as *fetch* function.

## Installation

Install it with npm:

```
npm i react-custom-fetch-hook --save
```



### Error handling

The `useFetch` hook returns an `error` field at any fetch exception. 
The `error` field extends [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
and has `status` and `statusText` fields equal to [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response).

```javascript

function CustomHook() {
  const {data,loading ,error } = useFetch("https://quotable.io/quotes");

  if (error) {
    return <div>
      <p>Code: ${error.status}</p>
      <p>Message: ${error.statusText}</p>
    </div>
  }
};

```

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