DEV Community

Aman Kureshi
Aman Kureshi

Posted on

Lazy Loading in React β€” Load Only What You Need, When You Need It πŸš€

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)