# use-request-react

> Custom react-hook for data fetching

Latest version **1.0.0** (published 2019-12-03) · MIT license · 0 weekly downloads

## Install

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

## 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.0 |
| Published | 2019-12-03 |
| First published | 2019-12-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Boris Kachanov |
| Maintainers | kachanov_b |
| Keywords | react, hooks, fetch |

## Links

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

## 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.0 (latest) — 2019-12-03

## README

# useRequest

Custom React Hook for data fetching

## Installation

```sh
npm install use-request
```

## Usage example

```js
import React, { useState, useCallback } from 'react';
import axios from 'axios';
import { Formik, Form, Field } from 'formik';
import { useRequest } from 'use-request';

function App() {
  const [searchValue, setValue] = useState('');

  const fetchPeople = useCallback(
    () =>
      axios
        .get(`https://swapi.co/api/people/?search=${searchValue}`)
        .then(({ data: { results } }) => results),
    [searchValue]
  );

  const handleSubmit = useCallback(({ inputValue }) => setValue(inputValue), [setValue]);
  
  const [{ isLoading, data, error }, updateData] = useRequest(fetchPeople);

  return (
    <React.Fragment>
      <Formik initialValues={{ inputValue: '' }} onSubmit={handleSubmit}>
        <Form>
          <Field type="inputValue" name="inputValue" />
          <button type="submit">Submit</button>
          <button onClick={updateData}>update data</button>
        </Form>
      </Formik>
      {data.map(item => <p>{item.name}</p>)}
    </React.Fragment>
  );
}

export default App;
```

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