demarches-normaliennes/app/javascript/components/Loadable.js

25 lines
548 B
JavaScript
Raw Normal View History

import React, { Suspense, lazy } from 'react';
import PropTypes from 'prop-types';
2019-08-14 13:11:36 +02:00
const Loader = () => <div className="spinner left" />;
2019-08-14 13:11:36 +02:00
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} />;
};
2019-08-14 13:11:36 +02:00
}