Need help with async-reactor?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

xtuc
447 Stars 26 Forks MIT License 72 Commits 7 Opened issues

Description

Render async Stateless Functional Components in React

Services available

!
?

Need anything else?

Contributors list

# 2,750
Babel
ecmascr...
html5
React
53 commits
# 550,692
React
code-sp...
JavaScr...
1 commit
# 55,271
React
faceboo...
faceboo...
CSS
1 commit
# 65,757
box2d
unix
PHP
React
1 commit
# 50,168
Webpack
gatsby
gatsbyj...
Markdow...
1 commit

async-reactor

Render async Stateless Functional Components

Installation

npm install --save async-reactor

Usage

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

Using code splitting

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

function Loader() { return ( Loading ... ); }

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

return (

{time.format('MM-DD-YYYY')}
); }

export default asyncReactor(Time, Loader);

Using fetch

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

function Loader() {

return (

Loading ...

); }

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

return (

    {posts.map((x) =>
  • {x.title}
  • )}
); }

export default asyncReactor(AsyncPosts, Loader);

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.