@ozylog/async-component
v0.1.2
Published
Simple Async Component for React
Downloads
5
Readme
async-component
Simple Async Component for React
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