mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Interactivity and Dynamic UIs Docs page updated with ES6 Example (#6832)
* Interactivity and Dynamic UIs Pages ES6 Example
* Change bind handler
(cherry picked from commit c7ef0af54b)
This commit is contained in:
committed by
Paul O’Shannessy
parent
39d6f49896
commit
aa2edb427a
@@ -11,22 +11,26 @@ You've already [learned how to display data](/react/docs/displaying-data.html) w
|
||||
## A Simple Example
|
||||
|
||||
```javascript
|
||||
var LikeButton = React.createClass({
|
||||
getInitialState: function() {
|
||||
return {liked: false};
|
||||
},
|
||||
handleClick: function(event) {
|
||||
class LikeButton extends React.Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
liked: false
|
||||
}
|
||||
this.handleClick = this.handleClick.bind(this);
|
||||
}
|
||||
handleClick() {
|
||||
this.setState({liked: !this.state.liked});
|
||||
},
|
||||
render: function() {
|
||||
var text = this.state.liked ? 'like' : 'haven\'t liked';
|
||||
}
|
||||
render() {
|
||||
const text = this.state.liked ? 'like' : 'haven\'t liked';
|
||||
return (
|
||||
<p onClick={this.handleClick}>
|
||||
<div onClick={this.handleClick}>
|
||||
You {text} this. Click to toggle.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ReactDOM.render(
|
||||
<LikeButton />,
|
||||
|
||||
Reference in New Issue
Block a user