forked from FormidableLabs/react-flux-concepts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
004-props.html
85 lines (81 loc) · 1.76 KB
/
004-props.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!-- https://docs.google.com/drawings/d/1Z14zxr-6qQFtZGs3K-bzPs3SffZMYY3eMPGV_XWqayA/edit?usp=sharing -->
<!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>
<div id="app-container"></div>
<script type="text/jsx">
/**
*
* Assignment:
*
* 1. Look at this.props in console
* 2. Add another prop to a parent
* 3. Access that prop in the child and get it onto the screen
*
*/
var Recipe = React.createClass({
getInitialState: function () {
/* remember, we really invoked a function and passed in args. */
console.log(this.props)
/* Recipe.getInitialState(): must return an object or null */
return null;
},
render: function() {
return (
<div>
<h2> {this.props.title} </h2>
<p> {this.props.instructions} </p>
</div>
);
}
});
var RecipeList = React.createClass({
render: function() {
return (
<div>
RecipeList component text
<Recipe
title="Stuffed Chard"
instructions="Stuff the chard..."
/>
<Recipe
title="Eggplant and Polenta"
instructions="Put the eggplant in the oven..."
/>
</div>
);
}
});
var RecipeForm = React.createClass({
render: function() {
return (
<div >
RecipeForm component text
</div>
);
}
});
var RecipeBook = React.createClass({
render: function() {
return (
<div>
Hello, world! I am a RecipeBook.
<RecipeList/>
<RecipeForm/>
</div>
);
}
});
React.render(
<RecipeBook />,
document.getElementById('app-container')
);
</script>
</body>
</html>