Reputation: 551
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.
Upvotes: 9
Views: 10001
Reputation: 18803
For Remote debugger
console.ignoredYellowBox = ['Remote debugger'];
and for all warning
console.disableYellowBox = true;
Upvotes: 1
Reputation: 40643
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.
Upvotes: 1
Reputation: 760
To disable only this warning message use the following code on possible files
console.ignoredYellowBox = ['Warning: setState(...)'];
Upvotes: 2
Reputation: 32154
the better solution is to write this in your index
file:
console.disableYellowBox = true;
Upvotes: 11
Reputation: 7879
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).
Upvotes: 1
Reputation: 7106
To disable only the setState message
The "setState(...) Can only update a mounted or mounting component." is thrown from 4 possible files :
- node_modules/react/dist/react-with-addons.js
- node_modules/react/dist/react.js
- node_modules/react/lib/ReactNoopUpdateQueue.js
- 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
Upvotes: 1