프로젝트
GitHub에서 보기
xtuc/async-reactor
소개
React에서 비동기 Stateless Functional Components를 렌더링합니다
웹 및 앱 개발측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originalasync-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 (
<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
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);
관련 프로젝트 살펴보기
불러오는 중…