demarches-normaliennes/app/javascript/components/Loadable.js
2020-10-15 17:30:49 +02:00

24 lines
548 B
JavaScript

import React, { Suspense, lazy } from 'react';
import PropTypes from 'prop-types';
const Loader = () => <div className="spinner left" />;
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} />;
};
}