Skip to content

Commit 50c9569

Browse files
committed
함수형으로 변경
1 parent fbbb8d4 commit 50c9569

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

chapter7-3/src/PeopleList.js

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,12 @@
11
import React, {Component} from 'react';
22
import fetch from 'isomorphic-fetch';
3-
class PeopleList extends Component {
4-
constructor(props) {
5-
super(props);
6-
this.state = {
7-
data : [],
8-
loaded : false,
9-
loading : false
10-
}
11-
}
123

13-
componentWillMount() {
14-
this.setState({loading : true});
15-
fetch('https://randomuser.me/api/?results=10')
16-
.then(response=>response.json())
17-
.then(obj => obj.results)
18-
.then(data => this.setState({
19-
loaded : true,
20-
loading : false,
21-
data
22-
}));
23-
}
4+
const PeopleList = ({data}) =>
5+
<ol className="people-list">
6+
{data.results.map((person, i) => {
7+
const {first, last} = person.name;
8+
return <li key={i}>{first} {last}</li>
9+
})}
10+
</ol>
2411

25-
render() {
26-
const {data, loading, loaded} = this.state;
27-
return (loading) ?
28-
<div>데이터 로딩 중..</div> :
29-
<ol className="people-list">
30-
31-
</ol>
32-
}
33-
}
12+
export default PeopleList;

0 commit comments

Comments
 (0)