Sub topic 14
Standalone DevTools for React Native and embedded views
This chapter assumes you can use the Components and Profiler tabs in a browser. It also assumes you know how to start a React app in development mode.
Why the browser extension is not enough
The browser extension attaches to a page in a desktop browser. Some React code runs where no extension can attach:
- React Native apps on a simulator or a physical device
- React running inside a WebView or an embedded browser view
- Pages in a browser that has no extension support, such as Safari on iOS
For these cases React ships a standalone app, react-devtools. It has the same Components and Profiler tabs as the extension. It runs as its own desktop window and accepts connections from apps over a WebSocket.
How the connection works
The standalone app starts a server, by default on port 8097. Your app runs a small piece of code that connects to that server and sends it the component tree. Commands such as "edit this prop" travel back the same way.
Start the standalone app
You do not need to install it permanently. Run it with npx:
npx react-devtoolsA window opens and shows "Waiting for React to connect…". Leave it open while you start your app.
Connect a React Native app
In development, React Native tries to connect to localhost:8097 on its own. What you do depends on where the app runs:
- iOS simulator: nothing extra. The simulator shares your machine's network.
- Android emulator or USB device: forward the port so the device can reach your machine.
adb reverse tcp:8097 tcp:8097- Physical device on Wi-Fi: the app must connect to your computer's IP address. Install
react-devtools-corein the app and call it from your entry file, before anything else imports React:
import { connectToDevTools } from 'react-devtools-core';
if (__DEV__) {
connectToDevTools({ host: '192.168.1.20', port: 8097 });
}Replace 192.168.1.20 with your computer's address on the local network.
Newer React Native versions also include a built-in debugger opened from the dev menu. It has its own Components and Profiler panels. The standalone app remains useful when that debugger does not fit your setup, or when you debug something that is not React Native.
Connect an embedded web view
For React running inside a WebView or a browser without the extension, load the DevTools backend with a script tag. It must come before React loads:
<!DOCTYPE html>
<html>
<head>
<script src="http://localhost:8097"></script>
</head>
<body>
<div id="root"></div>
<script src="/bundle.js"></script>
</body>
</html>The standalone server serves this script itself. Remove the tag before you ship. A device that cannot reach localhost on your machine needs your computer's IP address in the URL instead.
Common errors
| Symptom | Likely cause |
|---|---|
| Window stays on "Waiting for React to connect" | The app cannot reach port 8097 (missing `adb reverse`, wrong IP, or a firewall) |
| Window connects, then the tree is empty | The backend loaded after React. Move it earlier. |
| Connected, but Profiler shows no data | The app is a production build. See the build modes chapter. |
| Old tree appears after a reload | Restart the app so it reconnects to the same window |
Exercise
Your React Native app runs on an Android emulator, but the standalone DevTools window still says "Waiting for React to connect". What command do you try first, and why?
Show answer
Run adb reverse tcp:8097 tcp:8097. The emulator has its own network, so localhost inside it is not your computer. The command forwards the emulator's port 8097 to the DevTools server on your machine.