# async-reactor

> Render async Stateless Functional Components

Latest version **1.2.2** (published 2017-11-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install async-reactor
pnpm add async-reactor
yarn add async-reactor
bun add async-reactor
```

## 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.2.2 |
| Published | 2017-11-24 |
| First published | 2017-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 442 |
| Author | Sven SAULEAU |
| Maintainers | xtuc |
| Keywords | react, stateless, functionnal, components, async, await, code-splitting, render |

## Links

- npm: https://www.npmjs.com/package/async-reactor
- Repository: https://github.com/xtuc/async-reactor
- Homepage: https://github.com/xtuc/async-reactor#readme
- Issues: https://github.com/xtuc/async-reactor/issues
- npm.io page: https://npm.io/package/async-reactor

## Dependencies (1)

- [react](https://npm.io/package/react.md) ^15.5.3

## 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.2.2 (latest) — 2017-11-24
- 1.2.1 — 2017-06-15
- 1.2.0 — 2017-05-09
- 1.1.2 — 2017-05-05
- 1.1.1 — 2017-04-24
- 1.1.0 — 2017-04-24
- 1.0.5 — 2017-04-16
- 1.0.4 — 2017-04-14
- 1.0.3 — 2017-04-13
- 1.0.2 — 2017-04-12
- 1.0.1 — 2017-04-11
- 1.0.0 — 2017-04-11

## README

# async-reactor

> Render async Stateless Functional Components

## Installation

```shell
npm install --save async-reactor
```

## Usage

```js
asyncReactor(component: Function, loader?: Component, error?: Component): Component
```

| name               | type             | description                                     |
|--------------------|------------------|-------------------------------------------------|
| component          | Function (async) | The `async` component you want to render        |
| loader (optionnal) | Component        | Will be shown until the first component renders |
| error (optionnal)  | Component        | Will be shown when an error occurred            |

The returned value is a regular `Component`.

### Examples

This examples are exporting a regular React component.
You can integrate it into an existing application or render it on the page.

See more examples [here](https://github.com/xtuc/async-reactor/tree/master/examples)

#### Using code splitting

```js
import React from 'react'
import {asyncReactor} from 'async-reactor';

function Loader() {
  return (
    <b>Loading ...</b>
  );
}

async function Time() {
  const moment = await import('moment');
  const time = moment();

  return (
    <div>
      {time.format('MM-DD-YYYY')}
    </div>
  );
}

export default asyncReactor(Time, Loader);
```

#### Using fetch

```js
import React from 'react';
import {asyncReactor} from 'async-reactor';

function Loader() {

  return (
    <h2>Loading ...</h2>
  );
}

async function AsyncPosts() {
  const data = await fetch('https://jsonplaceholder.typicode.com/posts');
  const posts = await data.json();

  return (
    <ul>
      {posts.map((x) => <li key={x.id}>{x.title}</li>)}
    </ul>
  );
}

export default asyncReactor(AsyncPosts, Loader);
```

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