React.lazy function. This is a technique known as lazy loading, which optimizes the performance of a website or application by loading only the necessary resources when they're needed, instead of downloading everything at once.React.lazy for route-based code-splitting:Home and About will be broken off into their separate bundles. These bundles will be loaded when any of the page routes attached to the component is loaded.React.lazy for component-based code-splitting. This is useful for components that are not attached to the application's page route, such as Modals and Asides.Note: you can ask me a follow up question by @ mentioning me again React.lazyReact.lazyReact.lazyHomeAboutimport React, { Suspense, lazy } from "react";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
const Home = React.lazy(() => import("./Home"));
const About = React.lazy(() => import("./About"));
const App = () => (
<Router>
<Suspense>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
</Routes>
</Suspense>
</Router>
);