-
Notifications
You must be signed in to change notification settings - Fork 0
/
Access.jsx
73 lines (69 loc) · 1.94 KB
/
Access.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
{
/*
Access Props Using this.props
The last several challenges covered the basic ways to pass props to child components. But what if the child component that you're passing a prop to is an ES6 class component, rather than a stateless functional component? The ES6 class component uses a slightly different convention to access props.
Anytime you refer to a class component within itself, you use the this keyword. To access props within a class component, you preface the code that you use to access it with this. For example, if an ES6 class component has a prop called data, you write {this.props.data} in JSX.
Render an instance of the Welcome component in the parent component App. Here, give Welcome a prop of name and assign it a value of a string. Within the child, Welcome, access the name prop within the strong tags.
*/
}
class App extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
{/* Change code below this line */}
<Welcome />
{/* Change code above this line */}
</div>
);
}
}
class Welcome extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
{/* Change code below this line */}
<p>
Hello, <strong></strong>!
</p>
{/* Change code above this line */}
</div>
);
}
}
// Solution
class App extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
{/* Change code below this line */}
<Welcome name="Mark Sikaundi" />
{/* Change code above this line */}
</div>
);
}
}
class Welcome extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
{/* Change code below this line */}
<p>
Hello, <strong>{this.props.name}</strong>!
</p>
{/* Change code above this line */}
</div>
);
}
}