replace deprecated react-loadable with suspense

This commit is contained in:
Paul Chavard 2020-10-13 17:04:51 +02:00
parent 59f4c8f7d8
commit ca0ba4ba2d
4 changed files with 22 additions and 17 deletions

View file

@ -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} />;
};
}