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.
i had this issue. The simple solution is to add latest versions of typescript, react-scripts libs. and then run npm install. it works for me.
As of January 19, 2021, Facebook React Native SDK will no longer be officially supported by Facebook. Please visit our blog post for more information and Github for React Native going forward.
The Yellow warning box in React Native can be both helpful and annoying. There are many errors that can be ignored but end up blocking necessary pieces of the application. To disable the yellow box place console. disableYellowBox = true; anywhere in your application.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With