Lazy loading helps you optimize performance by loading components only when theyโre needed, not upfront. It's perfect for large apps where not everything should be loaded at once.
๐ง Why use lazy loading?
โข Reduces initial bundle size
โข Improves app speed and performance
โข Better user experience on slow networks
๐ฆ React provides React.lazy() and Suspense for lazy loading components.
๐ง Example:
import React, { Suspense } from "react";
const LazyAbout = React.lazy(() => import("./About"));
function App() {
return (
<Suspense fallback={<p>Loading...</p>}>
<LazyAbout />
</Suspense>
);
}
๐ Key points:
โข Wrap lazy components in
โข Use a fallback UI like a loader or message
โข Great for routes, modals, and large UI blocks
Lazy loading helps deliver faster, more efficient React apps without sacrificing features.
Top comments (0)