Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print console log in reactnative Android?

Tags:

react-native

I am using below code to print console log in react native, but i am getting error cannot find variable v:

import React, 
{
AppRegistry,
Component,
StyleSheet,
Text,
View,

} from 'react-native';
var ConsolePanel = require('react-native-console-panel').displayWhenDev();


class RanD extends Component {
render() {
return (
    <View style={styles.container}>

          <Text>
          Hit me!
          </Text>

          <View>
          {ConsolePanel}
          </View>
    </View>
  );
  }
 }

how to resolve this error??

like image 265
animesh Avatar asked Apr 20 '16 17:04

animesh


People also ask

How do I print a console log in React Native?

For the android emulator, Click on the emulator screen and Press Control + M ( Ctrl + M ), After open the dialog option select Remote JS Debugging. This will open a resource, http://localhost:8081/debugger-ui on localhost. From there, use the Chrome Developer tools JavaScript console to view console. log() .

How do I use the console in React Native app?

You can access the developer menu by shaking your device or by selecting "Shake Gesture" inside the Hardware menu in the iOS Simulator. You can also use the ⌘D keyboard shortcut when your app is running in the iOS Simulator, or ⌘M when running in an Android emulator on macOS and Ctrl+M on Windows and Linux.

How do I see console log in react JS?

Take the following React code: function Element() { //Code is OK const variable = 1; console. log('1'); //Bug HERE while (true); console.


1 Answers

Remove this line:

var ConsolePanel = require('react-native-console-panel').displayWhenDev();

And also remove:

{ConsolePanel}

To log something to the console in React Native, simply do this:

console.log('Hi from React Native');

To see the console output, if you're on Mac OS or Linux, run this in a terminal window:

$ adb logcat | grep ReactNativeJS

If you're on Windows, see this StackOverflow question: How to easily view and filter Android's logcat in Windows?

Reading the logs is also documented in the Getting Started guide.

UPDATE: You can now run react-native log-ios or react-native log-android to see the logs in the console.

like image 142
Martin Konicek Avatar answered Jan 01 '23 23:01

Martin Konicek