7

I got a plenty of warnings while using Stylesheet in React Native as following image.

Warning on iOS simulator

How to suppress it?

William Han
  • 189
  • 1
  • 2
  • 7

3 Answers3

8

There is no way to disable warnings for a specific component, but you can disable different types of warnings in your app. To disable all warnings, use:

console.disableYellowBox = true;

To disable only certain warnings that start with a given string, specify an array of prefixes to filter out:

console.ignoredYellowBox = ['Warning: ...'];

For example, for the warning in the question you could write:

console.ignoredYellowBox = [
  'Warning: You are manually calling a React.PropTypes validation',
];
ide
  • 19,942
  • 5
  • 64
  • 106
  • @ide do i need to put this directly into my componenets like this render() { console.disableYelowBox = true; return ( ); }, – Waleed Arshad Sep 01 '16 at 11:06
  • 1
    Put it somewhere that runs when your app boots up. Grep for disableYellowBox and look at the implementation for a better idea. – ide Sep 01 '16 at 18:35
  • @WaleedArshad I put `console.ignoredYellowBox` above main component class's definition. – William Han Sep 02 '16 at 02:28
  • wow, this is making my propType checks utterley useless. Unfortunately React doesn't throw an exception when it fails against a propType check so I have to look around in the warnings. Unfortunately the warnings are being polluted by some third party. This is making my typechecking in react utterly utterly useless. – Oliver Watkins Mar 30 '18 at 14:25
  • You should update your answer to the new YellowBox API. `console.ignoredYellowBox` does not work anymore. – Elmar Zander Apr 14 '20 at 17:01
4

YellowBox API have changed from ReactNative 0.52:

To totally disable YellowBox: console.disableYellowBox = true;

To ignore some warnings:

import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Warning text here...']);

https://facebook.github.io/react-native/docs/debugging#warnings

TeChn4K
  • 2,317
  • 2
  • 21
  • 23
0

In React v0.63 its been updated again.

import { LogBox } from 'react-native';

LogBox.ignoreLogs(['Warning text here...']);
GollyJer
  • 23,857
  • 16
  • 106
  • 174