Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expected a component class, got [object Object]

Tags:

react-native

I get an error with this code. However, changing to react-native's removes the error. Can you use div with react-native? If not, why is this error so obscure...?

var React = require('react');
var ReactNative = require('react-native');
var {
  StyleSheet,
  Text,
  View,
} = ReactNative;

let Auto = React.createClass({
  getInitialState: function() {
    return { value: 'Ma' }
  },
  render: function() {
    return (
      <div className="fuck-react">
        Blah blah blah
      </div>
    )
  }

});

like image 681
Drew Avatar asked Jul 07 '16 05:07

Drew


3 Answers

No you cannot use div tag in react-native. Since, react-native is based on JSX syntax which are automatically dispatched to native components by abstract Dom parser. you can get your answer here:https://facebook.github.io/react-native/docs/tutorial.html

Also, react-native is upadated to new version that is 0.29 , you probably should ignore old ECMA script and use new ECMA script for javascript syntax. Since, react-native uses reactjs for its javascript so better learn from here: http://reactjs.net/guides/es6.html

like image 130
Chiranjhivi Ghimire Avatar answered Nov 18 '22 01:11

Chiranjhivi Ghimire


Instead of DIV use View.

<View style={{flex: 1}}>
       <Text>Blah blah blah</Text>
</View>
like image 27
Jagadish Upadhyay Avatar answered Nov 18 '22 00:11

Jagadish Upadhyay


You can not use in react native. Use native component instead.

<View>
  <Text>text text text</Text>
</View>

Do not forget to import before with:

import {
  Text,
  View
} from 'react-native';
like image 1
llioor Avatar answered Nov 18 '22 00:11

llioor