No, for every component it no needed. It make sense to use for each layout or page. A good place to start is with routes. Most people on the web are used to page transitions taking some amount of time to load. You also tend to be re-rendering the entire page at once so your users are unlikely to be interacting with other elements on the page at the same time.
For example, you creating application for news aggregator. Your application include two pages such as NewsList
and NewsItemPage
. Every pages includes several different components. In this example make sense to use lazy loading component for each other page. And then it will load the components it needs.
The application also has a Header
and Footer
. They should be loaded in the usual way. Since they are used on every page, and there is no point in asynchronous loading.
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import React, { Suspense, lazy } from 'react';
import Header from './components/Header';
import Footer from './components/Footer';
const NewsList = lazy(() => import('./pages/NewsList'));
const NewsItemPage = lazy(() => import('./pages/NewsItemPage'));
const App = () => (
<Router>
<Header />
<Suspense fallback={<div>Loading...</div>}>
<Switch>
<Route exact path="/" component={NewsList}/>
<Route path="/news/:id" component={NewsItemPage}/>
</Switch>
</Suspense>
<Footer />
</Router>
);