LogBox and the Console tell you that something went wrong. The other panels of React Native DevTools let you stop the app on a line, read the props and state a component actually rendered with, and see each request the app sent. They cover the React and JavaScript side of the app, and they don't replace the native tools in Android Studio and Xcode.
Key terms
- Sources panel: the DevTools panel that shows your app's source files and where you register breakpoints.
- React Components panel: the DevTools panel for inspecting and updating the rendered React component tree.
- Network panel: the DevTools panel that lists the requests your app makes, with timings, headers and response previews.
- Initiator tab: the tab of a network request that shows the call stack where the request started in your app.
Breakpoints in the Sources panel
A breakpoint is a line where the app pauses, so you can inspect its live state and step through the code. In the Sources panel, open a file from the sidebar or with Cmd + P or Ctrl + P, then click in the line number column next to the line. While the app is paused, the device shows a "Paused in Debugger" overlay, and tapping it resumes the app. The panels on the right show the current scope and the call stack and let you set watch expressions, and the controls at the top right step through the code.
Line breakpoints aren't the only kind. DevTools also offers Conditional Breakpoints and Logpoints.
Pausing from your editor
Finding the right file in the sidebar is slow when you already have it open in your editor. A debugger; statement written there acts as a breakpoint, and it reaches the device immediately through Fast Refresh. The ReorderButton example puts one at the top of its press handler.
Tap the button and execution stops on debugger; before fetch runs. The scope panel then shows orderId, reorderUrl and the current status, and you can step over the fetch call to see where the handler goes next. Remove the statement once you've found what you were looking for.
Checking what a component received
The React Components panel has all the features of the React DevTools browser extension. Hovering or selecting an element in the panel highlights it on the device. To go the other way, from something on screen to its component, click the "Select element" button at the top left and tap the element in the app.
The right-hand panel then shows that component's props and state, and you can change both while the app runs. This splits a rendering bug in two. If a cart row shows the wrong total, select the row and read its props. A wrong prop means the bug is upstream, in whatever passed the data down. A correct prop means the row itself renders it wrong. Editing a value in place also lets you check how a component looks with data that is hard to reach through the UI.
Requests in the Network panel
The Network panel has been in React Native DevTools since 0.83. It records requests automatically while DevTools is open, so open DevTools before you trigger the request you want to see. Each entry shows timings, the headers sent and received, and a preview of the response. For the ReorderButton POST, that is where you confirm whether the Authorization header went out, and the Initiator tab shows the call stack in your code that started the request.
The panel records calls made through fetch(), XMLHttpRequest and <Image>. Requests from custom networking libraries such as Expo Fetch aren't covered yet, and apps using Expo keep seeing a separate Expo Network panel that Expo implements. WebSocket events, response mocking and simulated network throttling aren't supported. Response previews are kept in an on-device buffer of at most 100MB, and when it fills, the oldest previews are evicted while the request metadata stays.
When the debugging connection closes
DevTools loses the app when the app is closed, a new native build is installed, the app crashes on the native side, Metro is quit, or a physical device is disconnected. It then shows a dialog with the message "Debugging connection was closed".
Dismiss it with the close icon or by clicking outside the dialog, and you're back in the DevTools UI in the state it was in before the disconnect. Once you've dealt with the cause, such as restarting Metro, select "Reconnect DevTools".
Code Examples
import { useState } from 'react';
import { Button, Text, View } from 'react-native';
type ReorderButtonProps = {
orderId: string;
reorderUrl: string;
authToken: string;
};
export function ReorderButton({ orderId, reorderUrl, authToken }: ReorderButtonProps) {
const [status, setStatus] = useState('idle');
async function handleReorder() {
debugger;
setStatus('sending');
const response = await fetch(reorderUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${authToken}`,
},
body: JSON.stringify({ orderId }),
});
setStatus(response.ok ? 'sent' : `failed with ${response.status}`);
}
return (
<View>
<Button title="Reorder" onPress={handleReorder} />
<Text>{status}</Text>
</View>
);
}