How can I log a variable in React Native, like using console.log
when developing for web?
You can use Reactotron also, it will give you lot more functionality than just logging. https://github.com/infinitered/reactotron
react-native-xlog module that can help you,is WeChat's Xlog for react-native. That can output in Xcode console and log file, the Product log files can help you debug.
Xlog.verbose('tag', 'log');
Xlog.debug('tag', 'log');
Xlog.info('tag', 'log');
Xlog.warn('tag', 'log');
Xlog.error('tag', 'log');
Xlog.fatal('tag', 'log');
There are several ways to achieve this, I am listing them and including cons in using them also. You can use:
console.log
and view logging statements on, without opting out for remote debugging option from dev tools, Android Studio and Xcode. or you can opt out for remote debugging option and view logging on chrome dev tools or vscode or any other editor that supports debugging, you have to be cautious as this will slow down the process as a whole.console.warn
but then your mobile screen would be flooded with those weird yellow boxes which might or might not be feasible according to your situation.console.log("My log text")
in your codeIn Android:
In IOS:
Where you want to log data use
console.log("data")
And to print this log in terminal use command for android
npx react-native log-android
and for iOS
npx react-native log-ios
If you are on osx and using an emulator, you can view your console.log
s directly in safari web inspector.
Safari => Development => Simulator - [your simulator version here] => JSContext