forked from FormidableLabs/react-flux-concepts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path004.1-collection-rendering.html
86 lines (82 loc) · 2.08 KB
/
004.1-collection-rendering.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
86
<!-- https://docs.google.com/drawings/d/1hippuxmqixmozTPXGE8Ma5h8GMApVKyaGZk5OYnonwE/edit?usp=sharing -->
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.12.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.12.2/JSXTransformer.js"></script>
</head>
<body>
<div id="app-container"></div>
<script type="text/jsx">
var Recipe = React.createClass({
render: function() {
return (
<div >
<h2> {this.props.title} </h2>
<p> {this.props.instructions} </p>
</div>
);
}
});
var RecipeList = React.createClass({
render: function() {
/**
* STEP 3: iterate over the data received in props,
* passing properties of each item into the collection
* into a unique child component.
*/
var recipeNodes = this.props.data.map(function(recipe, index){
/**
* each item in a collection needs a key... see:
* http://facebook.github.io/react/docs/multiple-components.html#dynamic-children
*/
return (
<Recipe
key={index}
title={recipe.title}
instructions={recipe.instructions} />
)
})
return (
<div>
RecipeList.
{recipeNodes}
</div>
);
}
});
var RecipeForm = React.createClass({
render: function() {
return (
<div >
RecipeForm.
</div>
);
}
});
var RecipeBook = React.createClass({
render: function() {
/* STEP 2: pass the recieved prop into the child component */
return (
<div>
Hello, world! I am a RecipeBook.
<RecipeList data={this.props.data}/>
<RecipeForm/>
</div>
);
}
});
window.recipeData = [
{title: "Stuffed Chard", instructions: "Stuff the chard..."},
{title: "Eggplant and Polenta", instructions: "Put the eggplant in the oven..."}
];
React.render(
/* STEP 1: pass the data into the controller view */
<RecipeBook data={window.recipeData} />,
document.getElementById('app-container')
);
</script>
</body>
</html>