-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
55 lines (46 loc) · 1.15 KB
/
App.js
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
import React, { Component } from 'react'
import PropTypes from "prop-types"
export default class App extends Component {
render() {
return (
<div>
<Person />
</div>
)
}
}
class Person extends Component {
state = {
people: [
{ /* name: "john", img: "https://randomuser.me/api/portraits/thumb/men/69.jpg", */ age: 20, id: 1 },
{ name: "wick", img: "https://randomuser.me/api/portraits/thumb/men/90.jpg", age: 22, id: 2 },
{/* img: "https://randomuser.me/api/portraits/thumb/men/41.jpg", */ name: "jack", age: 20, id: 3 }
]
}
render() {
return (
<div>
{this.state.people.map((item) => <Persons name={item.name} img={item.img} age={item.age} key={item.id} />)}
</div>
)
}
}
Persons.propTypes = {
img: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
age: PropTypes.number.isRequired,
}
Persons.defaultProps = {
name: "steve",
age: 24,
img: "https://randomuser.me/api/portraits/thumb/men/51.jpg",
}
function Persons({ name, img, age }) {
return (
<section>
<img src={img} />
<h2>{name}</h2>
<h3>{age}</h3>
</section>
)
}