How to disable react native warning message at the bottom

前端 未结 6 1147
予麋鹿
予麋鹿 2021-01-12 04:16

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 underst

6条回答
  •  时光取名叫无心
    2021-01-12 05:12

    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
    

提交回复
热议问题