Use Suspense to handle the loading state while the component is loading.?
import React, { Suspense } from 'react';
const LazyComponent = React.lazy(() => import('./LazyComponent'));
function App() {
return (
<Suspense fallback={<div>Loading...</div>}>
<LazyComponent />
</Suspense>
);
}
- React.lazy enables dynamic imports for code splitting.
- Suspense lets you specify a loading state while waiting for the component to load.