React.memo prevents re-renders of unchanged components. lazy() enables code splitting.
Getting Started
What is React?
Components & Props
Components & Props
Performance & Testing
React.memo & Lazy Loading
Custom Hooks
Building Custom Hooks
Error Boundaries
Error Handling
Server Components
React Server Components
Next.js Introduction
Next.js Basics
Animations & Transitions
Framer Motion
React
Intermediate
FREE
React.memo & Lazy Loading
Lesson 1 of 17
Intermediate
Interactive
Syntax
REACT
const MemoizedComponent = React.memo(MyComponent); const LazyComponent = React.lazy(() => import('./MyComponent'));
React.memo and Lazy Loading
REACT
import React, { memo, lazy, Suspense } from "react"; const HeavyComponent = memo(function HeavyComponent({ data }) { console.log("Rendering HeavyComponent"); return <div>{data}</div>; }); const LazyComponent = lazy(() => import("./LazyComponent")); function App() { return ( <div> <HeavyComponent data="Hello" /> <Suspense fallback={<p>Loading...</p>}> <LazyComponent /> </Suspense> </div> ); }
Practice
1
Exercise
Practice this concept.
Answer
Write the code as shown above.
Quick Quiz
1
What did you learn?
This covers the basics.
Interview Questions
It is a fundamental React feature.