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 : .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.
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.
Share Improve this question edited Jan 29, 2016 at 22:21 Dmitry Shvedov 3,2964 gold badges40 silver badges56 bronze badges asked Oct 12, 2013 at 15:06 DjangoRocksDjangoRocks 14.2k7 gold badges38 silver badges52 bronze badges1 Answer
Reset to default 17Ok, 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!