Sub topic 1
What React Developer Tools Shows That the Browser Tools Do Not
Prerequisites
This chapter assumes you can do the following:
- Write React function components and pass props to them.
- Use
useStatein a component. - Open the Elements and Console panels in your browser's developer tools.
- Run a React app locally in development mode.
You do not need to install anything yet. The next chapter covers installation.
The gap between the DOM and your components
The browser's Elements panel shows the DOM, which is the tree of HTML nodes the browser renders. React builds that DOM from your components, but the DOM keeps none of the structure you wrote. A <List> containing several <Item> components appears as a plain ul with li children. The component names, props, and state are gone.
React Developer Tools reads React's internal tree instead. It shows what your code describes: components, the props each one received, the state each one holds, and the hooks it calls.
The Console has a similar limit. You can log a value you already suspect is wrong, but you must edit code, reload, and log again to look at another one.
What you can see in React Developer Tools
React Developer Tools adds two tabs to your browser's developer tools, Components and Profiler.
| Question | Elements panel | Components tab | Profiler tab |
|---|---|---|---|
| Which component produced this node? | Not shown | Shown as a tree | Not the focus |
| What props did a component get? | Not shown | Listed per component | Shown for a commit |
| What is in a component's state? | Not shown | Listed, with hooks | Not the focus |
| Which components re-rendered, and how long did it take? | Not shown | Highlight updates option | Recorded per commit |
| Why did a component render? | Not shown | Not shown | Shown if enabled |
A commit is the moment React applies a batch of changes to the DOM. The Profiler groups its measurements by commit.
A concrete example
Suppose a list shows the wrong selected item. In the Elements panel you see only li elements and a p with the text "Selected: none". Nothing there tells you which component owns the selection value.
In the Components tab you select List and see its useState hook with the value null. You select an Item and see its label and onSelect props. One view answers where the state lives and which props reach each child.
You can also read the selected component from the Console. React Developer Tools exposes it as $r.
// In the Components tab, select a component, then switch to the Console:
$r.props; // props of the selected component
$r.type; // the component function or class itselfLater chapters cover this in detail.
What it does not replace
React Developer Tools does not replace the browser tools. Use the Elements panel for CSS and layout, the Network panel for requests, and the Console for errors. React Developer Tools covers only the component layer.
Where this fits in the tutorial
The tutorial follows two paths. The Components tab helps you find incorrect data, such as a wrong prop or stale state. The Profiler tab helps you find slow or unnecessary renders. The final chapter combines both into one repeatable workflow.
Exercise
A page shows the text "Selected: none" even after you click an item. Why is the Elements panel a poor place to find which component holds the selection state, and which React Developer Tools tab would you open first?
Show answer
The Elements panel shows only the rendered DOM nodes. Component names, props, and state are not part of the DOM, so it cannot show which component owns the state. Open the Components tab first, select the component that renders the text, and read its hooks and props.
Exercise
Name one task where the browser's Elements or Network panel is still the better tool than React Developer Tools.
Show answer
Inspecting CSS and layout (Elements panel) or checking an API request and its response (Network panel). React Developer Tools only shows the component layer.