-
Notifications
You must be signed in to change notification settings - Fork 0
/
tuto2.html
39 lines (38 loc) · 1 KB
/
tuto2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!-- index.html -->
<html>
<head>
<title>Hello React</title>
<script src="http://fb.me/react-0.12.2.js"></script>
<script src="http://fb.me/JSXTransformer-0.12.2.js"></script>
<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
</head>
<body>
<div id="example"></div>
<script type="text/jsx">
var LikeButton = React.createClass({
getInitialState: function() {
//this.props.liked=false;
return {liked: false};
},
handleClick: function(event) {
console.log(this.state);
//this.props.liked=!this.props.liked;
this.setState({liked: !this.state.liked});
},
render: function() {
console.log(this.state.liked);
var text = this.state.liked ? 'like' : 'haven\'t liked';
return (
<p onClick={this.handleClick}>
You {text} this. Click to toggle.
</p>
);
}
});
React.render(
<LikeButton />,
document.getElementById('example')
);
</script>
</body>
</html>