How do React.lazy and dynamic import() enable code splitting?

It tests your grasp of React code-splitting and the Suspense contract. A strong answer states that lazy defers loading until first render via dynamic import, and Suspense shows a fallback while the Promise resolves.
It tests your understanding of React code-splitting and the Suspense boundary contract. A strong answer covers four things in order: first, lazy takes a loader returning a dynamic import Promise; second, React calls the loader only on first render and caches the Promise and resolved module; third, the resolved default export must be a valid React component; fourth, Suspense catches the thrown Promise and renders a fallback until resolution. A red flag is conflating Suspense with generic loading states or believing lazy preloads before mount.
Read the original → react.dev
- #react
- #suspense
- #code-splitting
- #lazy
- #performance
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.