How do you hide the warnings in React Native iOS simulator?

我的梦境 提交于 2019-12-02 16:27:36
Moussawi7

According to React Native Documentation, you can hide warning messages by setting disableYellowBox to true like this:

console.disableYellowBox = true;
Southerneer

A better way to selectively hide certain warnings (that indefinitely show up after an upgrade to the latest and greatest RN version) is to set console.ignoredYellowBox in a common JS file in your project. For example, after upgrading my project today to RN 0.25.1 I was seeing a lot of...

Warning: ReactNative.createElement is deprecated...

I still want to be able to see helpful warnings and error messages from React-Native, but I want to squash this particular warning because it's coming from an external npm library that hasn't yet incorporated the breaking changes in RN 0.25. So in my App.js I add this line...

// RN >= 0.52
import {YellowBox} from 'react-native';
YellowBox.ignoreWarnings(['Warning: ReactNative.createElement']);

// RN < 0.52
console.ignoredYellowBox = ['Warning: ReactNative.createElement'];

This way I still get other errors and warning helpful for my dev environment, but I no longer see that particular one.

To disable the yellow box place

console.disableYellowBox = true; 

anywhere in your application. Typically in the root file so it will apply to both iOS and Android.

For example

export default class App extends React.Component {
     render() {
          console.disableYellowBox = true;
          return (<View></View>);
     }
}

Add the following code in your index.js file

console.disableYellowBox = true;

    import {AppRegistry} from 'react-native';
    import App from './App';
    import {name as appName} from './app.json';

    console.disableYellowBox = true;



AppRegistry.registerComponent(appName, () => App);

For those coming this way trying to disable red warnings from the console, that give absolutely useless information, as of feb/17, you can add this line of code somewhere

console.error = (error) => error.apply;

Disables all console.error

If You're Trying to Quickly Demo the App.

If you want to hide them in a particular build because you're doing a demo or something, you can edit your Xcode scheme to make it a release build and these yellow warnings will not show up. Additionally, your app will run much faster.

You can edit the Scheme for your simulator and real device by doing the following:

  1. In Project in XCode.
  2. Product > Scheme > Edit Scheme...
  3. Change Build Configuration from Debug to Release.

To disable the yellow box place console.disableYellowBox = true; anywhere in your application. Typically in the root file so it will apply to both iOS and Android.

For get more details please check official document

console.disableYellowBox = true;

this worked for application level Put it anywhere in index.js file

In your app.js file under any component's lifecycle method.like in componentDidmount() you have to add both of these,excluding any will not work.

console.ignoredYellowBox = ['Warning: Each', 'Warning: Failed'];
console.disableYellowBox = true;

In your AppDelegate.m file you can change this line :

jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];

and replace dev=true by dev=false at the end.

Related: Suppress Xcode warnings from React Native library

(but not for your own code)

why: when initialising a new RN-app, the Xcode project contains closer to 100 warnings that is distracting noise (but probably harmless otherwise)

solution: set inhibit all warnings to yes under Build Settings for the relevant targets.

Disable warnings in Xcode from frameworks

https://github.com/facebook/react-native/issues/11736

console.ignoredYellowBox = ['Warning: Each', 'Warning: Failed'];

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!