React.lazy: Load Components On Demand

React.lazy tells your app: "Don't download this component's code until it's needed." It's a core tool for code splitting. Use it for below-the-fold content or modals to speed up initial load. The footgun: forgetting <Suspense> will crash your app.
Why it exists
By default, modern JavaScript bundlers often create a single, large bundle file containing all your application's code. This means users download code for features they might never use, slowing down the initial page load. React.lazy was created to solve this by enabling code-splitting at the component level.
The mental model
Think of React.lazy as on-demand loading for your UI components. Instead of importing everything upfront, you create a placeholder. When React attempts to render this placeholder for the first time, it triggers a background download for the actual component's code, rendering it only when it arrives.
How it works
You declare a lazy component by calling lazy() with a function that itself calls a dynamic import(). This import() function returns a Promise. When the lazy component is first rendered, React "suspends" that part of the UI tree. You must wrap the lazy component in a <Suspense> boundary and provide a fallback prop, which is a temporary UI (like a spinner) to show during the download. Once the Promise resolves, React renders the component from the module's default export. React caches the result, so the code is only fetched once.
When to use it
Use React.lazy for components that are not critical for the initial render. Good candidates include: modals and popups, complex charts or data visualizations, admin-only sections of an app, or any content that is "below the fold" and not immediately visible to the user. This strategy significantly improves initial load performance.
When not to use it
Avoid using React.lazy for small, simple components where the overhead of a network request might be slower than just including it in the main bundle. Do not use it for components that are always visible on the initial page load, like a site header or main navigation, as this would only delay their appearance unnecessarily.
One canonical example
A common use case is loading a heavy markdown editor that isn't needed immediately. Instead of a static import MarkdownEditor from './MarkdownEditor';, you declare it lazily: const MarkdownEditor = lazy(() => import('./MarkdownEditor'));. Then, in your component, you wrap it with Suspense: <Suspense fallback={Loading editor...}><MarkdownEditor /></Suspense>. The user sees 'Loading editor...' until the editor's code is fetched and ready to render.
Interview question
Which scenario best demonstrates an appropriate use case for React.lazy?
- a.A complex data visualization chart displayed within a tab that users might click later.Correct
- b.A site's main navigation bar, always visible at the top of every page.
- c.A small, reusable button component used frequently across the application.
- d.A critical hero section component that must appear instantly on page load.
Why? this is the answer
React.lazy is designed for components that are not critical for the initial render, such as complex charts or content "below the fold," to improve initial load performance. Components that are always visible or critical for immediate display should not be lazy-loaded, nor should small, simple components where the overhead outweighs the benefit.
Just read this? Test yourself on what you have been reading.
Read the original → react.dev
- #react
- #performance
- #code-splitting
- #suspense
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on react — each one lists the topics its interview covers.
See open roles