As React applications grow larger, performance becomes very important.
Performance optimization helps:
Faster page loading
Better user experience
Reduced unnecessary rendering
Improved application efficiency
React provides several optimization techniques: React.memo, useMemo, useCallback, lazy loading, and code splitting.
React.memo
What is React.memo?
React.memo is a Higher Order Component (HOC) used to prevent unnecessary re-rendering of components. A component wrapped with React.memo only re-renders when its props change.
Benefits: Prevents unnecessary function recreation, improves rendering performance, useful with React.memo.
Difference Between useMemo and useCallback
Hook
Purpose
useMemo
Memoizes values
useCallback
Memoizes functions
Lazy Loading in React
What is Lazy Loading?
Lazy loading loads components only when needed. Instead of loading all components initially, React loads components dynamically. This reduces initial loading time and bundle size.
React.lazy Example
JSXimport React, { Suspense } from "react";
const Home = React.lazy(() => import("./Home"));
function App() {
return (
<div>
<Suspense fallback={<h2>Loading...</h2>}>
<Home />
</Suspense>
</div>
);
}
export default App;
Use React.memo — Avoid unnecessary component rendering
Use useMemo — Optimize expensive calculations
Use useCallback — Prevent unnecessary function recreation
Use lazy loading — Load components dynamically
Use code splitting — Reduce bundle size
Optimize images — Use compressed images and modern formats
Avoid unnecessary state — Keep state minimal
Real-World Use Cases
Technique
Use Case
React.memo
Large component trees
useMemo
Filtering large data
useCallback
Passing functions to child components
Lazy Loading
Dashboard pages
Code Splitting
Large applications
Summary
In this tutorial, you learned:
React.memo
useMemo
useCallback
Lazy loading
Code splitting
These optimization techniques help React applications become faster, efficient, scalable, and user-friendly. Performance optimization is very important in modern React development.
React Performance Optimization MCQ Practice
10 Basic MCQs10 Advanced MCQs
10 Basic React Performance Optimization MCQs
1
React.memo wraps:
AComponent to skip re-render if props unchanged
BRouter
Cnpm
DCSS file
Explanation: Shallow compare props by default.
2
useMemo returns:
AMemoized computed value
BMemoized component always
CDOM node
DRouter
Explanation: Recalculate only when deps change.
3
useCallback returns:
AMemoized function reference
BMemoized number only
CCSS
DPromise
Explanation: Stable callback for child memo deps.
4
React.lazy loads:
AComponent code on demand
BAll bundles upfront
CCSS only
DImages only
Explanation: Code splitting with dynamic import.
5
Suspense fallback shows:
AUI while lazy component loads
BError only
CRedux store
DRouter config
Explanation:<Suspense fallback={<Spinner />}>.
6
Unnecessary re-renders often caused by:
ANew object/function props each render
BUsing keys
CUsing fragments
DUsing JSX
Explanation: Inline {} and () => create new references.
7
Virtual DOM helps by:
AMinimizing real DOM updates
BRemoving JavaScript
CDisabling state
DUsing SQL
Explanation: Diff + reconcile batch DOM writes.
8
Profiling React app uses:
AReact DevTools Profiler
BOnly console.log
CCSS inspector only
Dpackage.json
Explanation: Record commits to find slow renders.
9
key prop on lists helps performance by:
ACorrect reconciliation
BMaking CSS faster only
CDisabling state
DRemoving fetch
Explanation: Stable keys avoid expensive DOM moves.
10
Colocating state:
AKeep state close to where needed
BPut everything in Redux always
CUse global for checkbox
DDelete components
Explanation: Limits re-render subtree scope.
10 Advanced React Performance Optimization MCQs
1
React 18 startTransition marks updates as:
ANon-urgent lower priority
BBlocking always
CServer-only
DCSS
Explanation: Keep input responsive during heavy UI updates.
2
useDeferredValue is for:
ADeferring expensive render based on lagging value
BFetching only
CRouting
DKeys
Explanation: Show stale UI while preparing new expensive tree.