6

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??

animesh
  • 141
  • 2
  • 3
  • 12

1 Answers1

19

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.

Community
  • 1
  • 1
Martin Konicek
  • 39,126
  • 20
  • 90
  • 98
  • hi Martin Konicek .I just place console.log('Hi from React Native'); like this console.log('Hi from React Native'); . I am getting error console.log('Hi from React Native') must be wrapped in explicit component. – animesh Apr 21 '16 at 18:09
  • I placed console.log after import statement .It'sWork.thanks @Martin Konicek – animesh Apr 21 '16 at 18:19
  • adb invocation failed. Do you have adb in your PATH? i am getting this error please help me @Martin Konicek – Vijendra patidar Nov 24 '18 at 18:06