Facebook React.js Example Error?

I am trying to find the Facebook Reactjs library and found it great. I went through an exam / textbook and got his job.

Now I am: http://facebook.imtqy.com/react/docs/interactivity-and-dynamic-uis.html

And I tried 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 executing the code above, I get nothing. In my Chrome Chrome console, the error I received was Uncaught SyntaxError: Unexpected token < , in a line starting with <p onClick={this.handleClick}>

I was wondering if there is anyone who can enlighten me about what is wrong with the code?

Best wishes.

+7
javascript facebook reactjs
source share
1 answer

Well, I know what the mistake was.

Since I put the code in my question as an external file (Like.js), make sure the script tag should look like this:

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

Requires "text / jsx"!

Thanks!

+17
source share

All Articles