# react-promise-suspense

> React hook for resolving promises with Suspense support

Latest version **0.3.4** (published 2023-02-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-promise-suspense
pnpm add react-promise-suspense
yarn add react-promise-suspense
bun add react-promise-suspense
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.3.4 |
| Published | 2023-02-12 |
| First published | 2019-03-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 163 |
| Author | Vignesh M |
| Maintainers | vigzmv |
| Keywords | react, fetch, suspense, promise, hooks |

## Links

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

## Dependencies (1)

- [fast-deep-equal](https://npm.io/package/fast-deep-equal.md) ^2.0.1

## 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.3.4 (latest) — 2023-02-12
- 0.3.3 — 2020-05-03
- 0.3.2 — 2019-12-09
- 0.3.1 — 2019-08-01
- 0.3.0 — 2019-03-11
- 0.2.1 — 2019-03-11
- 0.2.0 — 2019-03-11

## README

# usePromise

React hook for resolving promises with Suspense support.

Inspired by [fetch-suspense](https://github.com/CharlesStover/fetch-suspense), but this one is not limited to fetch, `usePromise` works with any Promise.

[![version](https://img.shields.io/npm/v/react-promise-suspense.svg)](https://www.npmjs.com/package/react-promise-suspense)
[![minified size](https://img.shields.io/bundlephobia/min/react-promise-suspense.svg)](https://www.npmjs.com/package/react-promise-suspense)
[![minzipped size](https://img.shields.io/bundlephobia/minzip/react-promise-suspense.svg)](https://www.npmjs.com/package/react-promise-suspense)
[![downloads](https://img.shields.io/npm/dt/react-promise-suspense.svg)](https://www.npmjs.com/package/react-promise-suspense)

## Install

* `npm install react-promise-suspense --save`

## Example

- Here's an [Codesandbox example](https://codesandbox.io/s/react-promise-suspense-example-t14mh) of a setTimeout delayed component. 

- Awaiting a fetch promise:
```js
import usePromise from 'react-promise-suspense';

const fetchJson = input => fetch(input).then(res => res.json());

const MyFetchingComponent = () => {
  // usePromise(Promise, [inputs,],)
  const data = usePromise(fetchJson, [
    'https://pokeapi.co/api/v2/pokemon/ditto/',
    { method: 'GET' },
  ]);

  return <pre>{JSON.stringify(data, null, 2)}</pre>;
};

const App = () => {
  return (
    <Suspense fallback="Loading...">
      <MyFetchingComponent />
    </Suspense>
  );
};
```

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