最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Facebook React.js Example error? - Stack Overflow

programmeradmin3浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 17

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!

发布评论

评论列表(0)

  1. 暂无评论