Bucky Ďroid Bucky Ďroid - 1 month ago 23
React JSX Question

Getting error near div tag

I am new to react js..

When i run it i am getting syntax near tag i don't know why.. :(

<script type="text/babel">
var movie = react.createClass({
render:function(){
return{
<div>
<h1>{this.props.movietitle}</h1>
<h3>{this.props.moviegenre}</h3>
</div>
};
}
});
ReactDOM.render(
<div>

<movie movietitle="Avatar" moviegenre="Action" />

</div>,document.getElementById('takevalue'));
</script>

Answer

Your should have () for wrapping the return. Not the {}. And React components must be capitalized(<Movie/>)

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="takevalue"></div>
<script type="text/babel">
  var Movie = React.createClass({
    render:function(){
      return(
        <div>
          <h1>{this.props.movietitle}</h1>
          <h3>{this.props.moviegenre}</h3>
        </div>
      )
    }
  })
  ReactDOM.render(
  <div>
    <Movie movietitle="Avatar" moviegenre="Action" />
  </div>,document.getElementById('takevalue'));
</script>

You need Babel to convert jsx into js.

Hope this helps!