How to disable react native warning message at the bottom

前端 未结 6 1107
予麋鹿
予麋鹿 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:06

    Just to answer to question you asked, no, the warning will not show up when you load from a pre-bundled file (like when testing with TestFlight).

    0 讨论(0)
  • I edited my App.js file and added this:

    console.ignoredYellowBox = ['Warning: Can only update a mounted', '-[EXCamera updateFocusDepth'];
    

    You can provide an array of things you want to ignore. Simply provide a prefix of ones you want to ignore, no '*' or other wildcard required.

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2021-01-12 05:15

    the better solution is to write this in your index file:

    console.disableYellowBox = true;
    
    0 讨论(0)
  • 2021-01-12 05:16

    To disable only this warning message use the following code on possible files

    console.ignoredYellowBox = ['Warning: setState(...)'];
    
    0 讨论(0)
  • 2021-01-12 05:21

    For Remote debugger

    console.ignoredYellowBox = ['Remote debugger'];
    

    and for all warning

    console.disableYellowBox = true;
    
    0 讨论(0)
提交回复
热议问题