Skip to article content
FrontendXLesson 30 / 40

Profiling and React DevTools

Build, explain and debug React 19 interfaces: components, rendering, state, effects, identity, forms and actions, server components, concurrency, performance and testing, ending with architecture and typing work on real component challenges.

advanced · about 55 minutes · 4 exercises

  • Predict
  • Implement
  • Debug
  • Interview

What you will be able to do

#
  • Record an interaction and read the profiler output.
  • Identify why a component rendered using DevTools.
  • Measure a change before and after to prove it helped.

Overview

#

Measure before you optimize

Performance work starts with evidence. The React DevTools Profiler records an interaction and shows which components rendered, how long each commit took and what caused the render. Optimize what the profiler flags, not what you guess.

Reading the profiler

The flamegraph shows the render tree for a commit, with width proportional to time. The ranked view sorts components by how long they took. Clicking a component shows why it rendered: props changed, state changed, or the parent rendered.

The Profiler component

Wrap a subtree in the Profiler component to measure it programmatically. onRender receives the id, phase and duration, which you can log or send to analytics.

snippet.tsx
<Profiler id="feed" onRender={(id, phase, actualDuration) => {
  track('render', { id, phase, actualDuration });
}}>
  <Feed />
</Profiler>

The Components panel

The Components panel shows the props, state and hooks of the selected component, which is often faster than adding logs. You can also inspect why a memo did not help by checking whether props changed by reference.

React 19 performance tracks

React 19 can emit performance tracks that appear in the browser performance panel, aligning React work with browser tasks such as layout and paint. This helps you see whether the cost is React rendering or browser work.

Pitfall: optimizing by feel

Without a recording, it is easy to memoize the wrong component or add useMemo where it costs more than it saves. Always record before and after and compare the same interaction.

Pitfall: chasing render count

A component rendering often is not automatically a problem. What matters is the time and whether the render causes visible jank. Optimize the expensive renders, not the frequent ones.

Exercises

#

Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.

  1. Exercise 1Predict

    The profiler shows a component rendered but its props did not change. Why?

    Read the code, then choose the best answer. The reference explanation stays hidden until you respond.
    stimulus.tsx
    // parent re-rendered, child is not memoized
    Choose the best answer
  2. Exercise 2Implement

    Wrap a feed in the Profiler component and report each render.

    starter.tsx
    function App() {
      return <Feed />;
    }

    Reveal the reference answer
    reference.tsx
    import { Profiler } from 'react';
    
    function App() {
      return (
        <Profiler id="feed" onRender={(id, phase, actualDuration) => {
          track('render', { id, phase, actualDuration });
        }}>
          <Feed />
        </Profiler>
      );
    }

    Authored expected output: Each commit of the feed reports its id, phase and duration.

    The Profiler component calls onRender after each commit of its subtree with the measured duration, which you can log or send to analytics to track real-user performance.

  3. Exercise 3Debug

    A developer added useMemo everywhere and the page got slower. Explain and fix.

    starter.tsx
    const a = useMemo(() => x + 1, [x]);
    const b = useMemo(() => y * 2, [y]);

    Reveal the reference answer
    reference.tsx
    const a = x + 1;
    const b = y * 2;

    Authored expected output: The trivial computations run directly; memoization is reserved for measured heavy work.

    useMemo has a cost: it stores a dependency array and compares it each render. For cheap computations that cost exceeds the savings. Profile first, then memoize only what the recording shows is expensive.

  4. Exercise 4Interview

    Walk through how you would find and fix a performance problem in a React app.

    starter.tsx
    // record, read flamegraph, identify cause, fix, re-record

    Reveal the reference answer
    reference.tsx
    Start by reproducing the slow interaction and recording it in the React DevTools Profiler. Read the flamegraph and ranked view to find the components that take the most time, and use why-did-this-render to see whether the cause is props, state or a parent render. Fix the dominant cause first: move state down if a parent re-renders unrelated subtrees, stabilize props if memo is defeated, or virtualize if too many rows render. For each change, re-record the same interaction and compare commit durations. Only keep a change that the measurement supports.

    Authored expected output: A method: reproduce, record, identify the cause, fix the dominant cost, re-measure.

    The answer should be evidence-driven and iterative, with re-measurement as the proof that a change helped.

Common misconceptions

#
  • More renders always means slower. What matters is render cost and visible jank, not the count.
  • You can optimize without measuring. Profile first; guessing leads to wasted memoization.
  • useMemo always helps. It adds cost and can be slower for cheap computations.
  • The profiler only shows time. It also shows why each component rendered.

Follow-up practice

#
  • react-memoization-strategies
  • react-compiler-and-purity

Related resources

#

Your progress

#

Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.

Verification: authored. Answers and outputs on this page are authored reference material, not executed results.

© 2026 FrontendX. All rights reserved.