且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在底部禁用反应本机警告消息

更新时间:2022-10-15 17:30:05

仅禁用 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