简体   繁体   中英

expected expression, got '<' : Babel JSX processing doesn't work

I'm tying to make a clickable button with ReactJS using JSX with this code:

    'use strict';

class LikeButton extends React.Component {
  constructor(props) {
    super(props);
    this.state = { liked: false };
  }

  render() {
    if (this.state.liked) {
      return 'You liked this.';
    }

    return (
      <button onClick={() => this.setState({ liked: true }) }>
        Like
      </button>
    );
  }
}

let domContainer = document.querySelector('#like_button_container');
ReactDOM.render(<LikeButton />, domContainer);

I don't understand why I get the error :

expected expression, got '<'

It's obvious that Babel isn't processing the JSX from my code, but it should be running so I don't really know what the look up at this point.

Thanks to anyone who tries to help!

我刚刚意识到,使用Babel处理器后,我的纯JS代码就复制了JSX版本。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM