React Coroutine is a small library which leverages the power of modern JavaScript to provide seamless way in creating stateful components with different purposes.
This library just use a coroutine as a React component. No API to learn and keep up to date, no additional workflows or blackboxes to worry about.
Install
Use NPM or Yarn to install the library from NPM registry.
npm install react-coroutine
Usage
import React from 'react';
import Coroutine from 'react-coroutine';
import Posts from 'PostAPI';
import PostList from 'PostList.react';
async function PostListCo() {
try {
const posts = await Posts.retrieve();
return <PostList posts={posts} />;
} catch (error) {
return <p>Unable to fetch posts.</p>;
}
}
export default Coroutine.create(PostListCo);
Requirements
Using latest babel-preset-env
you’re able to use React Coroutine with async
functions. This also covers current version of Create React App. You may
need to add babel-preset-stage-3
to your setup to be able to use async
generators.
License
React Coroutine licensed under the MIT.
The MIT License places almost no restrictions on what you can do with this lib. You are free to use it in commercial projects as long as the copyright is left intact.
Credits
Amazing awsm.css built by Igor Adamenko was used for making the website.
Code examples use FiraCode font family.