SuspenseUtils.jsx 658 B

1234567891011121314151617181920212223
  1. /* eslint-disable import/prefer-default-export */
  2. import React, { Suspense } from 'react';
  3. /**
  4. * If you throw a Promise in the component, it will display a sppiner
  5. * @param {object} Component A React.Component or functional component
  6. */
  7. export function withLoadingSppiner(Component) {
  8. return (props => function getWithLoadingSpinner() {
  9. return (
  10. // wrap with <Suspense></Suspense>
  11. <Suspense
  12. fallback={(
  13. <div className="my-5 text-center">
  14. <i className="fa fa-lg fa-spinner fa-pulse mx-auto text-muted"></i>
  15. </div>
  16. )}
  17. >
  18. <Component {...props} />
  19. </Suspense>
  20. );
  21. });
  22. }