React — Code Splitting with React.lazy
Code splitting helps load parts of your app only when needed, improving performance. React provides React.lazy
and Suspense
for lazy loading components.
import React, { Suspense, lazy } from 'react';
const LazyComponent = lazy(() => import('./LazyComponent'));
function App() {
return (
<Suspense fallback={<div>Loading...</div>}>
<LazyComponent />
</Suspense>
);
}