渲染异步无状态功能组件 - async-reactor

2017-04-11      407      JavaScript
项目简介

async-reactor

渲染异步无状态功能组件

安装

npm install --save async-reactor

示例

component.js:

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

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

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

export default asyncReactor(AsyncPosts);

index.js:

import React from 'react';
import ReactDOM from 'react-dom';

import App from './component';

ReactDOM.render(
    <App />,
    document.getElementById('root')
);