Course contentsShow
← React
Lesson 940 of 2,39624. React.memoFree lesson

Real-World Example: Dashboard Widgets

Walk through a dashboard scenario where memoizing independent widgets prevents unnecessary re-renders.

Real-World Example: Dashboard Widgets

You'll learn: How memoizing independent dashboard widgets prevents wasteful re-renders when unrelated data updates.

Imagine a typical admin dashboard with multiple widgets: a sales chart, user statistics panel, notification feed, and weather widget. Each widget displays different data and updates at different times.

Without optimization, when any widget's data changes (say, new notifications arrive), the entire dashboard re-renders—forcing React to re-calculate and compare the sales chart, user stats, and weather widget even though their data hasn't changed. This creates unnecessary work, especially if those widgets perform expensive calculations or render complex visualizations.

The Dashboard Scenario

Your parent <Dashboard> component holds state for all widgets. When setNotifications() runs, the entire component re-renders. Each widget receives its data as props:

<Dashboard>
  <SalesChart data={salesData} />
  <UserStats data={userData} />
  <NotificationFeed data={notifications} />  {/* Only this changed */}
  <WeatherWidget data={weatherData} />
</Dashboard>

Without React.memo, all four widgets re-render even though three have identical props.

The Solution: Independent Memoization

Wrap each widget with React.memo:

const SalesChart = React.memo(({ data }) => {
  // Expensive chart rendering...
});

Now when notifications update, React performs shallow prop comparison on each widget. SalesChart, UserStats, and WeatherWidget receive the same data references, so React skips rendering them entirely. Only NotificationFeed re-renders.

This pattern works beautifully because dashboard widgets are typically independent: they don't share logic or interact with each other's state. Each widget becomes an isolated optimization boundary.

Key Takeaway: Dashboard widgets are ideal React.memo candidates—independent components with stable props that shouldn't re-render when unrelated dashboard sections update.