AsyncComponent
The goal of this section is to create a higher-order component that helps us with code splitting.
This component will only load its dependencies when it is rendered, or when we explicitly tell it to. This means that if we pass it LoginContainer.js, it will only load that file when the user navigates to /login, or if we tell it to load it.
In other words, this component will give us complete control over when our JavaScript files are loaded and opens up the world of lazy loading. However, it also means that whenever a route is rendered, the relevant files will be automatically loaded.
If that sounds abstract, let's see it in action.
Create a new file in your components/ directory called AsyncComponent.js and add the basic skeleton, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access