# @codefeathers/use-promise

> Fetch data with React Hooks

Latest version **0.2.1** (published 2020-09-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @codefeathers/use-promise
pnpm add @codefeathers/use-promise
yarn add @codefeathers/use-promise
bun add @codefeathers/use-promise
```

## 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.2.1 |
| Published | 2020-09-19 |
| First published | 2020-01-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 2.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Muthu Kumar |
| Maintainers | mkrhere |
| Keywords | React, Hooks, use, fetch, data, promise |

## Links

- npm: https://www.npmjs.com/package/@codefeathers/use-promise
- Repository: https://github.com/codefeathers/react-use-promise
- Homepage: https://github.com/codefeathers/react-use-promise#readme
- Issues: https://github.com/codefeathers/react-use-promise/issues
- npm.io page: https://npm.io/package/@codefeathers/use-promise

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) ^2.0.1
- [@types/react](https://npm.io/package/@types/react.md) ^16.9.49

## 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

- 0.2.1 (latest) — 2020-09-19
- 0.2.0 — 2020-09-03
- 0.1.1 — 2020-01-23
- 0.1.0 — 2020-01-23

## README

# React use-promise

Use React Hooks to resolve a promise; a wrapper around useState and useEffect for data-fetching.

## Installation

```bash
npm i @codefeathers/use-promise
```

## Usage

```JSX
import { usePromise } from "@codefeathers/use-promise";

const Search = () => {

	const [ search, setSearch ] = useState("");

	// if the Promise rejects, error is set, otherwise response is set
	const [ response, error, loading ] = usePromise(
		// Function that returns a Promise
		() => fetch(`/api/search?s=${search}`).then(x => x.json()),
		// default state of response
		[],
		// List of dependencies to watch for
		[ search ],
	);

	return <>
		<input value={search} onChange={e => setSearch(e.target.value)} />
		{loading ? <p>Loading...</p> : ""}
		{error ? <p>There was an error</p> :
			<ol>
				{response.map(each =>
					<li key={each.id}>{each.content}</li>)}
			</ol>
		}
	<>;

};
```

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