Suspense React Lazy code example

Example 1: suspense react

import React, {Suspense} from 'react;
const ProfilePage = React.lazy(() => import('./ProfilePage')); // Lazy-loaded

// Show a spinner while the profile [data fetching] is loading
<Suspense fallback={<Spinner />}>
  <ProfilePage />
</Suspense>

Example 2: lazy react

import React, { Suspense } from 'react';

const OtherComponent = React.lazy(() => import('./OtherComponent'));

function MyComponent() {
  return (
    <div>
      <Suspense fallback={<div>Loading...</div>}>
        <OtherComponent />
      </Suspense>
    </div>
  );
}