Interactivity and Dynamic UIs Docs page updated with ES6 Example (#6832)
* Interactivity and Dynamic UIs Pages ES6 Example * Change bind handler
Vedat Mahir YILMAZ committed
May 22, 2016 at 12:32 UTC
c7ef0af54b86f86acb2198bb2b7f921e205b06c3
1 file changed
+15
-11
docs/docs/03-interactivity-and-dynamic-uis.md
+15
-11
@@ -11,22 +11,26 @@ You've already [learned how to display data](/react/docs/displaying-data.html) w
11
## A Simple Example
12
13
```javascript
14
-var LikeButton = React.createClass({
15
- getInitialState: function() {
16
- return {liked: false};
17
- },
18
- handleClick: function(event) {
14
+class LikeButton extends React.Component {
15
+ constructor() {
16
+ super();
17
+ this.state = {
18
+ liked: false
19
+ }
20
+ this.handleClick = this.handleClick.bind(this);
21
+ }
22
+ handleClick() {
23
this.setState({liked: !this.state.liked});
20
- },
21
- render: function() {
22
- var text = this.state.liked ? 'like' : 'haven\'t liked';
24
+ }
25
+ render() {
26
+ const text = this.state.liked ? 'like' : 'haven\'t liked';
27
return (
24
- <p onClick={this.handleClick}>
28
+ <div onClick={this.handleClick}>
29
You {text} this. Click to toggle.
26
- </p>
30
+ </div>
31
);
32
}
29
-});
33
+}
34
35
ReactDOM.render(
36
<LikeButton />,