DjangoRocks
DjangoRocks

Reputation: 14198

Facebook React.js Example error?

I am tryin out Facebook's Reactjs library and found it awesome. I have ran through the exampe/tutorial and got it working.

Now i am at : http://facebook.github.io/react/docs/interactivity-and-dynamic-uis.html

And I am trying out the code:

/** @jsx React.DOM */

var LikeButton = React.createClass({
  getInitialState: function() {
    return {liked: false};
  },
  handleClick: function(event) {
    this.setState({liked: !this.state.liked});
  },
  render: function() {
    var text = this.state.liked ? 'like' : 'unlike';
    return (
      <p onClick={this.handleClick}>
        You {text} this. Click to toggle.
      </p>
    );
  }
});

React.renderComponent(
  <LikeButton />,
  document.getElementById('example')
);

After running the code above, i get nothing. In my google chrome console, the error i got was Uncaught SyntaxError: Unexpected token < , on the line starting with <p onClick={this.handleClick}>

I was wondering if there's anyone who can enlighten me as to what is wrong with the code ?

Best Regards.

Upvotes: 8

Views: 5715

Answers (1)

DjangoRocks
DjangoRocks

Reputation: 14198

Ok, i know what the mistake was.

Since i place the code in my question as an external file ( Like.js ), make sure that the script tag should read as follows:

<script type="text/jsx"  src="Like.js"></script>

The "text/jsx" is required!

Thanks!

Upvotes: 17

Related Questions