react-async-decorator
TypeScript icon, indicating that this package has built-in type declarations

0.2.8 • Public • Published

react-async-decorator

New way to organize your asynchronous flow in react applications. inspired by Dan Abramov: Beyond React 16.

Build Status

Getting Started

Installing

npm install react-async-decorator

If you prefer yarn

yarn react-async-decorator

Simple example

import { asyncClass, initFetchers } from 'react-async-decorator';
const config = initFetchers();
const fetcher = config.createFetcher(() => fetch('/data.json'));
 
// If you don't want to use decorators, it should be replaced next syntax
// const WrapTest = asyncClass(fetcher)(Test);
@asyncClass(fetcher)
class Test extends React.Component {
    render() {
        const data = fetcher.get();
        // This content will be rendered after success response of fetch request
        return <div>{data}</div>;
    }
    renderLoader() {
        // This content will be rendered while fetch request in progress
        return <div>Loading</div>;
    }
    renderError(err) {
        // This content will be rendered after fail response of fetch request
        return <div>{err.message}</div>;
    }
}

Documentation

Running the tests

All unit tests are in __tests__ folder. They are written with jest.

npm test

Contributing

We are happy any contributions. Please be aware of all unit-tests and linters passed.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository. Thanks for standard-version for automation.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Readme

Keywords

none

Package Sidebar

Install

npm i react-async-decorator

Weekly Downloads

2

Version

0.2.8

License

MIT

Unpacked Size

82.4 kB

Total Files

34

Last publish

Collaborators

  • lexich