Skip to content

Dragon0513/react-async-decorator

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published