# promise-react-component

> A utility React component that renders its contents based on lifecycle state of a specified Promise

Latest version **0.1.0** (published 2018-02-16) · MIT license · 0 weekly downloads

## Install

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

## 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.1.0 |
| Published | 2018-02-16 |
| First published | 2018-02-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 72.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Marc Høegh |
| Maintainers | mhoegh |

## Links

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

## Recent versions

- 0.1.0 (latest) — 2018-02-16
- 0.0.3 — 2018-02-16
- 0.0.2 — 2018-02-14
- 0.0.1 — 2018-02-14

## README

# Promise React Component

A utility React component that renders its contents based on lifecycle state of a specified Promise

## Installation

```bash
$ npm install --save promise-react-component
```

Or:

```bash
$ yarn add --save promise-react-component
```

## Usage

Simple example:

```javascript
import PromiseComponent from 'promise-react-component';
// ...

return (
  <PromiseComponent
    promise={myApi.fetchData()}
    resolved={MyComponent}
    rejected={MyErrorScreen}
    pending={MyLoadingSpinner}
  />
)
```

Advanced example:

```javascript
import PromiseComponent from 'promise-react-component';
// ...

return (
  <PromiseComponent
    promise={myApi.fetchData()}
    resolved={props =>
      props.route === '/some-route'
        ? <Some {...props} />
        : <Other {...props} />
      }
    rejected={error =>
      error.status === '404'
        ? <MyNotFoundScreen />
        : <MyErrorScreen>
      }
    pending={MyLoadingSpinner}
  />
)
```

** Note: All props are optional **

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