0.1.2 • Published 8 years ago
@ozylog/async-component v0.1.2
async-component
Simple Async Component for React
Installation
npm install @ozylog/async-componentUsage 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