Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable red screen in debug mode

Tags:

react-native

Using React Native I would like to keep working in debugor __DEV__ mode but without the red screens.

Does someone know how to disabled it or change console.error implementation?

I've tried to do something like this:

console.error = {};

Or

console.error = () => {};

But none of the above worked.

Any idea?

like image 320
gran33 Avatar asked Jun 27 '17 07:06

gran33


3 Answers

Use:

console.reportErrorsAsExceptions = false;

https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/Libraries/Core/ExceptionsManager.js#L97

Works for me.

like image 198
janziemba Avatar answered Nov 02 '22 16:11

janziemba


After reading the react-native code I managed to stop the red screen with

console._errorOriginal = console.error.bind(console); console.error = () => {};

like image 4
Matthew Lowry Avatar answered Nov 02 '22 17:11

Matthew Lowry


Add this to your app's entry point JS file:

import {NativeModules} from 'react-native';
NativeModules.ExceptionsManager = null;

It will disable the native module that's responsible for showing the red-box window (reportSoftException, or reportFatalException called from react-native/Libraries/Core/ExceptionsManager.js)

like image 3
Artal Avatar answered Nov 02 '22 18:11

Artal