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 between them.
- Use
useStateand know that a state update causes a re-render. - Use the browser's Elements and Console panels.
- Run a React app locally in development mode, for example with Vite or Create React App.
You don't need any DevTools experience. This chapter explains what the tool is for. Later chapters cover installation details, each panel, and the Profiler.
The problem: the browser sees output, not components
The browser's built-in tools know about the DOM, the network, and JavaScript execution. They don't know what React is. When you open the Elements panel on a React app, you see the HTML that React produced. The components that produced it are gone.
Consider this code:
import { useState } from 'react';
function Price({ amount, currency }) {
return <span className="price">{amount} {currency}</span>;
}
function Cart() {
const [quantity, setQuantity] = useState(2);
return (
<section>
<Price amount={quantity * 10} currency="EUR" />
<button onClick={() => setQuantity(quantity + 1)}>Add one</button>
</section>
);
}
export default Cart;The Elements panel shows this:
<section>
<span class="price">20 EUR</span>
<button>Add one</button>
</section>Suppose the price is wrong. The DOM can't tell you whether quantity is wrong, whether Price received the wrong amount, or whether Price formatted a correct value badly. The values in the DOM are already final text. The inputs that produced them are gone.
React Developer Tools is a browser extension that hooks into React itself. It reads the same component tree React keeps internally and presents it as a debugging interface.
What React Developer Tools adds
The extension adds two tabs to the browser's developer tools: Components and Profiler. Both show information that doesn't exist in the DOM.
| Question | Browser tools | React Developer Tools |
|---|---|---|
| Which component rendered this `<span>`? | Not shown. You see only the element. | The Components tab shows `Price` as the owner. |
| What props did `Price` receive? | Not shown. | Listed as `amount: 20` and `currency: "EUR"`. |
| What is the current state of `Cart`? | Not shown. | Listed under hooks as `State: 2`. |
| Can I change a value and see the result without editing code? | You can edit DOM text, but React overwrites it on the next render. | You can edit props, state, and hook values, and React re-renders from them. |
| Why did this component re-render? | Not shown. A Performance recording shows function calls but not component names or causes. | The Profiler records each commit and can report what changed. |
| How long did each component take to render? | Not shown per component. | The Profiler shows render time per component. |
The DOM tells you what the user sees. React Developer Tools tells you why React produced it.
The model: two trees
A React app has two parallel structures:
- The component tree, made of components such as
CartandPrice, plus wrappers like context providers. - The DOM tree, made of host elements such as
section,span, andbutton.
Many components produce no DOM node of their own. A context provider, a memo wrapper, or a component that only returns other components all appear in the component tree and are invisible in the DOM. Because the two trees differ in shape, you can't reliably rebuild the component tree by reading HTML.
React Developer Tools shows the left side with its data attached. The Elements panel shows the right side with none of it.
What you can read in the Components tab
When you select a component in the tree, the right-hand pane shows the following:
- Props: the values the parent passed down. For
Price, that isamountandcurrency. - Hooks: each hook the component called, in call order.
useStateappears asState, with its current value. Other hooks, such asuseRef,useMemo,useContext, anduseEffect, appear with their own labels. Custom hooks appear as named groups containing the hooks inside them. - Rendered by: the chain of components that created this one. This lets you trace a bad prop upward to the parent that computed it.
- Source: a link to where the component is defined, when the build includes the information.
For the cart example, selecting Price shows amount: 20. If the number is wrong, you look at the Rendered by chain, select Cart, and see State: 2. The state is correct, so the bug is in the calculation quantity * 10. You found that without adding a console.log or changing the source.
Class components show props and state instead of hooks. Their layout is otherwise the same.
What you can read in the Profiler tab
The Profiler records while you interact with the app. Each React update that reaches the screen is a commit. For every commit, the Profiler shows:
- which components rendered
- how long each one took
- which components were skipped
It can also report why a component rendered, such as changed props, changed state, or a parent re-render. You'll use this to find unnecessary renders in later chapters.
The browser's Performance panel records time too, but it measures JavaScript functions and browser work, not components. You'll see a long call stack inside React's internals. You won't see which of your components was slow.
Common errors and limits
The tabs don't appear. The extension only adds the tabs when it detects React on the page. Check these in order:
- Reload the page after installing the extension.
- Confirm the page really uses React.
- If the page is in an iframe, select that frame's context in the browser tools.
Names look like t or e. In a production build, a minifier shortens function names. The tree still works, but names are meaningless. Debug in a development build whenever you can.
The Profiler has no data or is limited. Production builds strip most of the profiling support. Use a development build, or a profiling build if you need realistic timings. The chapter on build modes covers this.
Edits disappear. Values you edit in DevTools are temporary. A reload resets them, and a parent's next render can overwrite edited props. They are a debugging aid, not a way to change the app.
The component isn't in the tree. Components that were never rendered, or that are hidden behind conditional logic that is currently false, don't appear. If it isn't rendered, it isn't there to inspect.
DevTools lags on huge trees. Large apps with thousands of components can make the panel slow. The search and filter features, covered in a later chapter, help here.
When to reach for which tool
Use the browser tools when the question is about the page itself:
- layout and CSS
- network requests and their timing
- JavaScript errors and breakpoints
- DOM output
Use React Developer Tools when the question is about React's data and rendering:
- "Is this component getting the props I expect?"
- "What is the state right now?"
- "Why did this render again?"
- "Which component is slow?"
Many bugs need both. A wrong label might be a prop problem, which belongs to React Developer Tools, or a CSS problem that hides the right text, which belongs to the Elements panel. A good first move is to check the DOM and then the props. If the DOM is right but looks wrong, the bug is in styling. If the DOM is wrong, move up to the component that produced it.
Exercise
A <span> on your page shows "20 EUR" but should show "30 EUR". The Elements panel shows only the final text. Name two things you can learn from the Components tab that the Elements panel can't tell you, and say how they help you find the bug.
Show answer
You can see the props the Price component received (for example amount: 20) and the state of its parent (for example State: 2 in Cart). If amount is 20 and the parent's state is correct, the calculation in the parent is wrong. If amount is already right and the output is wrong, the bug is inside Price. The "Rendered by" chain also lets you move from the child to the parent that supplied the value.
Exercise
Why can't you rebuild the component tree by reading the HTML in the Elements panel?
Show answer
The two trees differ in shape. Many components, such as context providers, memo wrappers, and components that only return other components, produce no DOM element of their own. The HTML also contains no component names, props, state, or hooks. Only React Developer Tools reads React's internal tree.