如何在底部禁用反应本机警告消息 [英] How to disable react native warning message at the bottom

查看:56
本文介绍了如何在底部禁用反应本机警告消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 react-native IOS 应用程序,该应用程序有时会发出警告消息setState(...) 只能更新已安装或正在安装的组件....",我明白消息是什么大概是AJAX调用时间过长造成的.

考虑到这个警告不会对APP造成任何严重的问题,我现在不想花太多时间来修复它,这个警告消息在从开发服务器加载时会出现在模拟器和手机中.我的问题是警告信息是否仍然会在产品模式下提示(从预捆绑文件加载)?如果它仍然出现,如何从配置中禁用此警告消息?

谢谢.

解决方案

仅禁用 setState 消息

setState(...) 只能更新已安装或正在安装的组件."从 4 个可能的文件中抛出:

<块引用>

  1. node_modules/react/dist/react-with-addons.js
  2. node_modules/react/dist/react.js
  3. node_modules/react/lib/ReactNoopUpdateQueue.js
  4. node_modules/react/lib/ReactUpdateQueue.js

我不知道是哪一个触发了你的,但你可以修改这些文件以不显示警告.如果您关心的是您的用户,即处于发布模式,那么 dev 标志为 false,这意味着不会看到任何警告消息.

禁用所有警告

要禁用警告,只需在您的 AppDelegate.m 中更改:

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

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

如果您使用的是预捆绑文件,则必须在捆绑时将 dev 指定为 false :

react-native bundle --dev false --entry-file index.ios.js --bundle-output ios/main.jsbundle --platform ios

I'm working on a react-native IOS app, and this app sometimes will raise a Warning message "setState(...) Can only update a mounted or mounting component. ...", I understand what the message is about, it is caused by the long time AJAX call.

Considering this warning will not cause any serious issue for the APP, I don't want to spend much time to fix it at this moment, this warning message will show up in both simulator and cellphone while loading from development server. My question is whether the warning message will still prompt in product mode (Load from pre-bundled file)? If it will still show up, how to disable this Warning message from configuration?

Thanks.

解决方案

To disable only the setState message

The "setState(...) Can only update a mounted or mounting component." is thrown from 4 possible files :

  1. node_modules/react/dist/react-with-addons.js
  2. node_modules/react/dist/react.js
  3. node_modules/react/lib/ReactNoopUpdateQueue.js
  4. node_modules/react/lib/ReactUpdateQueue.js

I don't know which one triggered yours, but you can modify those files to not show the warning. If your concern is for your users, that is to say in release mode, then the dev flag is false which means that will not see any warning messages.

To disable all warnings

To disable the warnings, just change this in your AppDelegate.m :

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

to

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

If you're using the pre-bundled file you'll have to specify dev as false when bundling :

react-native bundle --dev false --entry-file index.ios.js --bundle-output ios/main.jsbundle --platform ios

这篇关于如何在底部禁用反应本机警告消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆