A
A
Artem2016-01-21 17:49:57
React
Artem, 2016-01-21 17:49:57

How to use react without JSX?

This code throws an error

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' : 'have not liked';
    return (
      React.createElement('p', null, 'You {text} this. Click to toggle.')
    );
  }
});

ReactDOM.render(
  LikeButton,
  document.getElementById('content')
);

Uncaught Error: Invariant Violation: ReactDOM.render(): Invalid component element. Instead of passing a component class, make sure to instantiate it by passing it to React.createElement.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IvanDix, 2016-01-21
@Paramount1987

ReactDOM.render(React.createElement( LikeButton),
document.getElementById('content')
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question