30

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

});

1
  • 2
    In React-Native, View takes the place of Div so better use View!
    – Dlucidone
    Jul 7, 2016 at 6:14

4 Answers 4

28

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

3
  • 1
    there is newer version available for react-native : 0.29 .Check here: upgrade to latest
    – Riten
    Jul 7, 2016 at 5:56
  • Thanks for the explanation. Does packer automatically find files with extension jsx? What's the version have to do with this question? Does 0.29 provide better errors?
    – Drew
    Jul 7, 2016 at 17:02
  • React-native application is mainly based on syntax, so with the upgrading in react-native version the change in syntax is priotrized. So, we should adapt the change of JSX syntax while developing application. Jul 8, 2016 at 4:21
6

Instead of DIV use View.

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

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

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.