Sub topic 2
Installing the extension and opening the tabs
This chapter covers installing React Developer Tools, confirming it detects your app, and finding its two tabs. It assumes you can write React function components, use useState and props, and use the browser's Elements and Console panels. It also assumes you can run a React app locally in development mode.
What you are installing
React Developer Tools is a browser extension. It adds two panels to your browser's developer tools:
- Components shows the React component tree, with each component's props, state, and hooks.
- Profiler records renders and reports how long they took and why they happened.
The extension works because it puts a small object on the page before your app's code runs. React finds this object, called the global hook, and reports each render to it. The extension reads from the hook. This explains most installation problems: if the hook isn't present when React starts, or React never talks to it, the tabs won't appear.
Installing the extension
Official builds exist for the three main browser families:
| Browser | Where to get it |
|---|---|
| Chrome | Chrome Web Store, search for "React Developer Tools" |
| Edge | Microsoft Edge Add-ons store |
| Firefox | Firefox Add-ons site |
Check that the publisher is Meta (Facebook) before you install. Lookalike extensions exist, and this one can read your page's data.
Other environments need the standalone react-devtools package instead. Safari is one example. A later chapter in this tutorial covers that package.
Install steps are the same in each browser:
- Open the store page and choose the add or install button.
- Approve the permission prompt.
- Pin the extension's icon to the toolbar if your browser hides new extensions. You will use the icon to check detection.
Local files and private windows
Browsers restrict extensions in some contexts. These two cause the most confusion:
- Pages opened with
file://: In Chrome, open the extension's details page and turn on "Allow access to file URLs". Without it, an HTML file opened from disk never shows the tabs. A dev server such as Vite avoids this problem. - Private or incognito windows: Extensions are off by default. Enable them in the extension's settings for private browsing.
Running a test app
You need a React app in development mode to check the install. Any app works. If you don't have one, create one with Vite:
npm create vite@latest devtools-demo -- --template react
cd devtools-demo
npm install
npm run devOpen the local address that Vite prints, usually http://localhost:5173.
Replace src/App.jsx with a small component that has props and state, so later chapters have something to inspect:
import { useState } from 'react';
function Counter({ label }) {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
{label}: {count}
</button>
);
}
export default function App() {
return (
<main>
<h1>DevTools demo</h1>
<Counter label="Clicks" />
</main>
);
}Opening the tabs
Open your browser's developer tools with F12, Ctrl+Shift+I (Windows and Linux), or Cmd+Option+I (macOS). You can also right-click the page and choose Inspect.
Look along the tab bar for two new entries labeled Components and Profiler, each with an atom icon. If the window is narrow, the browser may hide them behind a » overflow button. Widen the panel or dock it to the side or bottom to see them.
Select Components. You should see a tree with App at the top and Counter nested inside it. The right-hand pane shows details for whichever component you select. Select Counter and you should see label: "Clicks" under props, plus a State entry under hooks. A later chapter covers how to read that pane. For now, finding it is enough.
The tabs are separate from the browser's own panels. The Elements panel shows DOM nodes, while Components shows React components. A component such as Counter has no DOM node of its own, so it never appears in Elements.
Reading the toolbar icon
The extension's toolbar icon tells you what it found on the current page, before you open any panel. Click it to see a short message.
| Icon state | Meaning |
|---|---|
| Gray or disabled | No React detected on this page |
| Colored, with a "development build" message | React detected, development build |
| Colored, with a "production build" message | React detected, production build |
The exact colors differ between browsers and versions, so rely on the message text. A page with a production build still lets you open the Components tab, but names may be minified, and some features are limited or missing. Production builds also have no warnings. The Profiler needs a profiling-enabled build. A later chapter covers build modes in depth. Here, just notice which message you get.
Checking the hook from the Console
When the tabs are missing, you can ask the page directly whether the hook exists and whether React registered with it. Run this in the Console:
const hook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
if (!hook) {
console.log('No DevTools hook: the extension is not active on this page.');
} else {
console.log('Hook found. React renderers attached:', hook.renderers.size);
}Read the result like this:
- No hook found: The extension isn't running on this page. Check the install, file URL access, or private window settings.
- Hook found, zero renderers: The extension is active, but no React renderer has attached. The page may not use React, or React may not have loaded yet.
- Hook found, one or more renderers: Detection works. If the tabs are still missing, reload the page with DevTools open.
The __REACT_DEVTOOLS_GLOBAL_HOOK__ name is an internal detail and could change between versions. Use it for diagnosis only, and never in application code.
When the tabs don't appear
Work through the causes in order, from most to least common.
A few of these deserve more detail:
- Opened DevTools after the page loaded. Usually this works, but if the panels stay empty, reload the page with DevTools already open. The tabs sometimes show a "Loading React Element Tree..." message that never clears until a reload.
- The page uses a different React. Some sites bundle React inside a separate frame or isolated context. The extension inspects the page it is attached to, so a React app in a cross-origin iframe may need that frame to be the inspected target. Embedded and native environments need the standalone tool.
- Several extensions conflict. Another extension that rewrites page scripts can interfere with the hook. Test in a clean browser profile to rule this out.
- Old extension version. A stale version may not understand features of newer React. Update the extension from your browser's extension page.
Settings worth knowing about
The gear icon at the right of the Components or Profiler toolbar opens the extension's settings. Right now, only the general options matter. You can choose a theme (light, dark, or follow the browser) and a display density for the tree. Other settings, such as component filters and render highlighting, come in later chapters. Leave them at their defaults until then, so your results match the later examples.
Summary of what you can now do
- Install the official extension for your browser and verify the publisher.
- Run a local development build and open the developer tools on it.
- Find the Components and Profiler tabs, including when they hide behind the overflow button.
- Read the toolbar icon to tell whether React was detected and which build type it is.
- Use the Console to check the DevTools hook when detection fails.
Exercise
You open DevTools on a page that you know is a React app, and the Components and Profiler tabs are missing. In the Console, window.__REACT_DEVTOOLS_GLOBAL_HOOK__ is defined, but window.__REACT_DEVTOOLS_GLOBAL_HOOK__.renderers.size is 0. What does this tell you, and what should you try first?
Show answer
The extension is installed and active on the page, because the hook exists. No React renderer has attached to it, so React has not loaded yet, or the React code runs somewhere the extension isn't inspecting, such as a separate frame. Reload the page with DevTools already open and check again. If the count stays at 0, confirm that the page really uses React and whether it renders inside an iframe or embedded view. In that case, use standalone DevTools.
Exercise
You open a local index.html file directly from disk in Chrome, with a React app built into it. The toolbar icon is gray. The extension is installed. What setting is the likely cause, and why does a dev server avoid the problem?
Show answer
Chrome blocks extensions on file:// pages unless you turn on "Allow access to file URLs" in the extension's details page. A dev server serves the page over http://localhost, which extensions can access without extra permission.