How can I log a variable in React Native, like using console.log
when developing for web?
There are 3 methods that I use to debug when developing React Native apps:
console.log()
: shows in consoleconsole.warn()
: shows in yellow box bottom of applicationalert()
: shows as a prompt just like it does in webChrome Devtool is the best and easiest way for logging and debugging.
Press [command + control + Z] in Xcode Simulator, choose Debug JS Remotely, then press [command + option + J] to open Chrome developer tools.
Xcode Simulator Img
refer:Debugging React Native Apps
You use the same thing that is used for regular web. The console
command also works in this case. For example, you can use console.log()
, console.warn()
,
console.clear()
etc.
You can use Chrome Developer to use the console
command when you're logging while you are running your React Native app.
console.log
works.
By default on iOS, it logs to the debug pane inside Xcode.
From the IOS simulator press (⌘+D) and press Remote JS Debugging. This will open a resource, http://localhost:8081/debugger-ui on localhost. From there use Chrome Developer tools javascript console to view console.log
Use console.debug("text");
You will see the logs inside the terminal.
Steps:
react-native run-ios # For iOS
react-native run-android # For Android
react-native log-ios # For iOS
react-native log-android # For Android