When a debug build hits a problem, LogBox is usually the first thing you see, an overlay React Native draws on top of your own screens. What it shows depends on the level of the log, and on Hermes it no longer shows every log that older guides describe. Knowing which messages reach the device and which only reach React Native DevTools saves you from waiting for a warning that never shows up.
Key terms
- LogBox: the in-app tool that appears when your app logs a warning or an error in a development build.
- React Native DevTools: the debugger for the JavaScript and React side of an app, built on the Chrome DevTools frontend.
- Console panel: the DevTools panel where you view and filter messages, evaluate JavaScript and inspect object properties.
LogBox.ignoreLogs: the LogBox method that keeps logs whose message matches a string or a regular expression out of LogBox.
Four levels of log
Every LogBox log has one of four levels: warn, error, fatal or syntax. An uncaught exception becomes a fatal log and opens LogBox full screen, the screen older material calls the redbox. Its footer has Dismiss, Minimize and Copy buttons, so you can close it and keep using the app.
A syntax log comes from code that can't be parsed. The latest syntax error is always shown ahead of every other log, and instead of buttons its footer reads "This error cannot be dismissed." None of your code can run until you fix it.
A console.error call produces an error log, shown as a notification at the bottom of the screen with a red badge. Consecutive logs from the same category roll up into one entry with a count. Tap the notification to open the expanded view and page through the other logs.
Getting into DevTools
Pick "Open DevTools" from the Dev Menu, or press j in the CLI. On iOS, when the app has lost its connection to Metro, that menu item reads "Connect to Metro to debug JavaScript" instead. DevTools first opens on a welcome panel with the console drawer open, and the other panels sit along the top of the window.
In a busy app, narrow the Console with the filter box or the log levels shown. Live Expressions watch a value over time, Preserve Logs keeps messages across reloads, and Ctrl + L clears the view.
Where console.warn goes on Hermes
Hermes is the default engine, and in a debug build it is compiled with its debugger turned on, on Android and on iOS. In that setup the runtime reports full console support, and LogBox drops every console.warn call. The warning still goes to the console, so you read it in the DevTools Console panel.
If no DevTools session is open, LogBox shows a single yellow notice in its place, "Open debugger to view warnings.", and tapping it opens the debugger. When a session starts, LogBox clears the warnings it held and leaves errors where they are.
Errors take a different path. React Native replaces console.error with its own handler, which forwards the call to the original console and then adds it to LogBox, so the red notification appears whether DevTools is open or not. Despite what the Debugging Basics page says, an open DevTools session doesn't hide non-fatal errors from LogBox. Warnings only get the yellow "Open debugger to view warnings." notice. LogBox options can also hide logs or change their level, so treat the Console panel as the complete record.
Silencing a log you can't fix
LogBox.ignoreLogs takes an array of patterns, each a string or a RegExp. A string matches any message that contains it, and a regular expression matches when its test() returns true. The patterns apply to warnings and to console errors, but since a Hermes debug build doesn't show warnings anyway, the log you'll see disappear is a dependency's console.error that keeps raising red notifications.
The index.js example below the lesson ignores two library messages. Adding a pattern re-checks the logs LogBox already holds, so the call works from anywhere in your code. Ignored messages still print to the console.
The string 'Analytics queue flushed twice' hides any message containing it, and /^\[legacy-charts\]/ hides every message that starts with that prefix. LogBox.ignoreAllLogs() turns off all notifications, and ignoreAllLogs(false) turns them back on, but an uncaught error still opens the full-screen LogBox.
Fixing an error without a reload
Fix a syntax error and save again, and the redbox goes away without a reload, because modules with syntax errors never run. After a runtime error while a module initializes, such as a typo in a call at the top of a file, the session continues once you fix it and the module is updated.
A runtime error inside a component also recovers once fixed, but React remounts the application with the updated code, which can send you to the root screen. Error boundaries retry rendering on the next edit after a redbox, which can keep you on the screen you were working on. Each Fast Refresh update also dismisses the redbox and clears all LogBox logs.
Code Examples
import { AppRegistry, LogBox } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
LogBox.ignoreLogs([
'Analytics queue flushed twice',
/^\[legacy-charts\]/,
]);
AppRegistry.registerComponent(appName, () => App);