forked from FormidableLabs/react-flux-concepts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
005.1-setState.html
63 lines (56 loc) · 1.43 KB
/
005.1-setState.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
</style>
<script src="http://fb.me/react-0.12.2.js"></script>
<script src="http://fb.me/JSXTransformer-0.12.2.js"></script>
</head>
<body>
<!--https://medium.com/react-tutorials/react-state-14a6d4f736f5
http://facebook.github.io/react/docs/tutorial.html#reactive-state -->
<script type="text/jsx">
/**
*
* Assignment:
*
* 1. Add a hover event to the div with the on click (http://facebook.github.io/react/docs/events.html)
* 2. Add a new callback that calls setState
* 3. Change something on screen (the text, etc.)
*
*/
var Recipe = React.createClass({
getInitialState : function() {
return {
dropDownIsOpen : false
};
},
handleClick : function() {
this.setState({
dropDownIsOpen : !this.state.dropDownIsOpen
});
},
renderDropdown: function () {
return (
<div style={{ background: "#ccc" }}>
I am a dropdown!
</div>
);
},
render : function() {
var dropdown = this.state.dropDownIsOpen ? this.renderDropdown() : null;
return (
<div onClick={this.handleClick}>
Click me!
{dropdown}
</div>
)
}
});
React.render(
<Recipe />,
document.body
);
</script>
</body>
</html>