Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Render async Stateless Functional Components in React

License

NotificationsYou must be signed in to change notification settings

xtuc/async-reactor

Repository files navigation

Render async Stateless Functional Components

Installation

npm install --save async-reactor

Usage

asyncReactor(component:Function,loader?:Component,error?:Component):Component
nametypedescription
componentFunction (async)Theasync component you want to render
loader (optionnal)ComponentWill be shown until the first component renders
error (optionnal)ComponentWill be shown when an error occurred

The returned value is a regularComponent.

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 exampleshere

Using code splitting

importReactfrom'react'import{asyncReactor}from'async-reactor';functionLoader(){return(<b>Loading ...</b>);}asyncfunctionTime(){constmoment=awaitimport('moment');consttime=moment();return(<div>{time.format('MM-DD-YYYY')}</div>);}exportdefaultasyncReactor(Time,Loader);

Using fetch

importReactfrom'react';import{asyncReactor}from'async-reactor';functionLoader(){return(<h2>Loading ...</h2>);}asyncfunctionAsyncPosts(){constdata=awaitfetch('https://jsonplaceholder.typicode.com/posts');constposts=awaitdata.json();return(<ul>{posts.map((x)=><likey={x.id}>{x.title}</li>)}</ul>);}exportdefaultasyncReactor(AsyncPosts,Loader);

About

Render async Stateless Functional Components in React

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp