-
Notifications
You must be signed in to change notification settings - Fork 0
/
Array.jsx
73 lines (68 loc) · 2.28 KB
/
Array.jsx
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
{
/*
Pass an Array as Props
The last challenge demonstrated how to pass information from a parent component to a child component as props or properties. This challenge looks at how arrays can be passed as props. To pass an array to a JSX element, it must be treated as JavaScript and wrapped in curly braces.
<ParentComponent>
<ChildComponent colors={["green", "blue", "red"]} />
</ParentComponent>
The child component then has access to the array property colors. Array methods such as join() can be used when accessing the property. const ChildComponent = (props) => <p>{props.colors.join(', ')}</p> This will join all colors array items into a comma separated string and produce: <p>green, blue, red</p> Later, we will learn about other common methods to render arrays of data in React.
There are List and ToDo components in the code editor. When rendering each List from the ToDo component, pass in a tasks property assigned to an array of to-do tasks, for example ["walk dog", "workout"]. Then access this tasks array in the List component, showing its value within the p element. Use join(", ") to display the props.tasksarray in the p element as a comma separated list. Today's list should have at least 2 tasks and tomorrow's should have at least 3 tasks.
*/
}
const List = (props) => {
{
/* Change code below this line */
}
return <p>{}</p>;
{
/* Change code above this line */
}
};
class ToDo extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<h1>To Do Lists</h1>
<h2>Today</h2>
{/* Change code below this line */}
<List />
<h2>Tomorrow</h2>
<List />
{/* Change code above this line */}
</div>
);
}
}
// solution
const List = (props) => {
{
/* Change code below this line */
}
return <p>{}</p>;
{
/* Change code above this line */
}
};
class ToDo extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<h1>To Do Lists</h1>
<h2>Today</h2>
{/* Change code below this line */}
{["walk", "eat", "barth"]}
<List />
<h2>Tomorrow</h2>
<List />
{/* Change code above this line */}
{["Code", "Coffee", "Sleep"]}
</div>
);
}
}