0.1.2 • Published 7 years ago

@ozylog/async-component v0.1.2

Weekly downloads
2
License
SEE LICENSE IN LI...
Repository
github
Last release
7 years ago

async-component

Simple Async Component for React

Travis npm

Installation

npm install @ozylog/async-component

Usage Example

'use react';

import createAsyncComponent from '@ozylog/async-component';
import DashboardLoaderComponent from './DashboardLoaderComponent';
import {isAuthenticated} from './authApi';

const DashboardContainer = createAsyncComponent({
  getComponent: async () => {
    let component;

    try {
      const isAuth = await isAuthenticated();

      if (isAuth) {
        component = await System.import('./../containers/DashboardContainer');
      } else {
        component = await System.import('./../components/ErrorForbiddenComponent');
      }
    } catch (err) {
      component = await System.import('./../components/ErrorInternalServerComponent');
    }

    return component;
  },
  LoaderComponent: DashboardLoaderComponent
});

export default (
  <Route path='/dashboard' render={() => <DashboardContainer />} />
);

License

MIT