File tree Expand file tree Collapse file tree 1 file changed +8
-29
lines changed Expand file tree Collapse file tree 1 file changed +8
-29
lines changed Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react' ;
2
2
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
- }
12
3
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 >
24
11
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 ;
You can’t perform that action at this time.
0 commit comments