Replaced react-loadable with @loadable/component
This commit is contained in:
@@ -1,39 +1,13 @@
|
||||
import React from 'react';
|
||||
import { Route } from 'react-router-dom';
|
||||
import Loadable from 'react-loadable';
|
||||
import loadable from '@loadable/component';
|
||||
|
||||
const Loading = props => {
|
||||
if (props.error) {
|
||||
return <p>{props.error}</p>;
|
||||
}
|
||||
const LazyRoute = props => {
|
||||
const { component, ...lazyProps } = props;
|
||||
|
||||
if (props.timedOut) {
|
||||
return (
|
||||
<div className='page'>
|
||||
<p>Page Timed Out</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const lazyComponent = loadable(component);
|
||||
|
||||
if (props.pastDelay) {
|
||||
return (
|
||||
<div className='page'>
|
||||
<p>Page Loading...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const LazyRoute = lazyProps => {
|
||||
const component = Loadable({
|
||||
loader: lazyProps.component,
|
||||
loading: Loading,
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
return <Route {...lazyProps} component={component} />
|
||||
return <Route {...lazyProps} component={lazyComponent} />
|
||||
};
|
||||
|
||||
export default LazyRoute;
|
||||
|
||||
Reference in New Issue
Block a user