replace deprecated react-loadable with suspense
This commit is contained in:
parent
59f4c8f7d8
commit
ca0ba4ba2d
4 changed files with 22 additions and 17 deletions
|
@ -1,8 +1,24 @@
|
|||
import React from 'react';
|
||||
import Loadable from 'react-loadable';
|
||||
import React, { Suspense, lazy } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const loading = () => <div className="spinner left" />;
|
||||
const Loader = () => <div className="spinner left" />;
|
||||
|
||||
export default function (loader) {
|
||||
return Loadable({ loader, loading });
|
||||
function LazyLoad({ component: Component, ...props }) {
|
||||
return (
|
||||
<Suspense fallback={<Loader />}>
|
||||
<Component {...props} />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
LazyLoad.propTypes = {
|
||||
component: PropTypes.object
|
||||
};
|
||||
|
||||
export default function Loadable(loader) {
|
||||
const LazyComponent = lazy(loader);
|
||||
|
||||
return function PureComponent(props) {
|
||||
return <LazyLoad component={LazyComponent} {...props} />;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue