你如何隐藏 React Native iOS 模拟器中的警告?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35309385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you hide the warnings in React Native iOS simulator?
提问by Some Guy
I just upgraded my React Native and now the iOS simulator has a bunch of warnings. Besides fixing them, how do I hide these warnings so that I can see what's underneath?
我刚刚升级了我的 React Native,现在 iOS 模拟器有一堆警告。除了修复它们,我如何隐藏这些警告以便我可以看到下面的内容?
回答by Moussawi7
According to React Native Documentation, you can hide warning messages by setting disableYellowBox
to true
like this:
根据反应本地文档,你可以通过设置隐藏警告消息disableYellowBox
,以true
这样的:
console.disableYellowBox = true;
回答by 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.ignoredYellowBoxin 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...
有选择地隐藏某些警告(在升级到最新和最好的 RN 版本后无限期显示)的更好方法是在项目的公共 JS 文件中设置console.ignoredYellowBox。例如,在今天将我的项目升级到 RN 0.25.1 之后,我看到了很多......
Warning: ReactNative.createElement is deprecated...
警告:不推荐使用 ReactNative.createElement...
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...
我仍然希望能够看到来自 React-Native 的有用警告和错误消息,但我想压制这个特殊警告,因为它来自一个外部 npm 库,该库尚未在 RN 0.25 中包含重大更改。所以在我的 App.js 中,我添加了这一行...
// 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.
这样我仍然会收到其他对我的开发环境有用的错误和警告,但我不再看到那个特定的错误和警告。
回答by Ragulan
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.
在您的应用程序中的任何地方。通常在根文件中,因此它适用于 iOS 和 Android。
For example
例如
export default class App extends React.Component {
render() {
console.disableYellowBox = true;
return (<View></View>);
}
}
回答by Abdul Basit
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.
在任何组件的生命周期方法下的 app.js 文件中。例如在 componentDidmount() 中,您必须添加这两个,排除任何将不起作用。
console.ignoredYellowBox = ['Warning: Each', 'Warning: Failed'];
console.disableYellowBox = true;
回答by Sarthak Mishra
Add the following code in your index.jsfile
在index.js文件中添加以下代码
console.disableYellowBox = true;
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);
回答by Joshua Pinter
If You're Trying to QuicklyDemo 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.
如果您想将它们隐藏在特定构建中,因为您正在做演示或其他事情,您可以编辑您的 Xcode 方案以使其成为发布构建,并且这些黄色警告不会显示。此外,您的应用程序将运行得更快。
You can edit the Scheme for your simulator and real device by doing the following:
您可以通过执行以下操作来编辑模拟器和真实设备的方案:
- In Project in XCode.
Product
>Scheme
>Edit Scheme...
- Change
Build Configuration
fromDebug
toRelease
.
- 在 XCode 的项目中。
Product
>Scheme
>Edit Scheme...
Build Configuration
从更改Debug
为Release
。
回答by SaGaR Patel
add this line in your app main screen.
console.disableYellowBox = true;
console.disableYellowBox = true;
回答by James Siva
console.disableYellowBox = true;
console.disableYellowBox = true;
this worked for application level Put it anywhere in index.js file
这适用于应用程序级别 将它放在 index.js 文件中的任何位置
回答by octohedron
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
对于以这种方式尝试从控制台禁用红色警告的人,这些警告提供了绝对无用的信息,截至 2 月 17 日,您可以在某处添加这行代码
console.error = (error) => error.apply;
console.error = (error) => error.apply;
Disables all console.error
全部禁用 console.error
回答by Vivek
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.
禁用黄色框放置console.disableYellowBox = true;
在您的应用程序中的任何位置。通常在根文件中,因此它适用于 iOS 和 Android。
For get more details please check official document
更多详情请查看官方文档