Drew
Drew

Reputation: 4691

expected a component class, got [object Object]

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>
    )
  }

});

Upvotes: 30

Views: 22489

Answers (4)

Hitesh Sahu
Hitesh Sahu

Reputation: 45072

You may be using ReactJS component in a React Native App. I accidentally installed a component with <div> tags in React Native project.

Upvotes: 0

llioor
llioor

Reputation: 6238

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';

Upvotes: 1

Jagadish Upadhyay
Jagadish Upadhyay

Reputation: 1264

Instead of DIV use View.

<View style={{flex: 1}}>
       <Text>Blah blah blah</Text>
</View>

Upvotes: 6

Chiranjhivi Ghimire
Chiranjhivi Ghimire

Reputation: 1739

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

Upvotes: 28

Related Questions