File tree 2 files changed +41
-2
lines changed 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change 1
- import React from 'react' ;
1
+ import React , { Component } from 'react' ;
2
2
import { render } from 'react-dom' ;
3
3
import { Router , browserHistory , Route } from 'react-router' ;
4
4
5
+ class List extends Component {
6
+ constructor ( props ) {
7
+ super ( props ) ;
8
+ this . state = { items : [ ] } ;
9
+ }
10
+
11
+ componentDidMount ( ) {
12
+ this . fetchList ( ) ;
13
+ }
14
+
15
+ fetchList ( ) {
16
+ fetch ( 'http://jsonplaceholder.typicode.com/users' )
17
+ . then ( res => {
18
+ return res . json ( ) ;
19
+ } )
20
+ . then ( data => {
21
+ console . log ( data ) ;
22
+ this . setState ( {
23
+ items : data
24
+ } ) ;
25
+ } )
26
+ . catch ( err => {
27
+ console . log ( err ) ;
28
+ } ) ;
29
+ }
30
+
31
+ render ( ) {
32
+ return (
33
+ < ul >
34
+ { this . state . items . map ( item => {
35
+ return < li key = { item . id } > { item . name } </ li > ;
36
+ } ) }
37
+ </ ul >
38
+ ) ;
39
+ }
40
+ }
41
+
5
42
const App = ( ) => {
6
43
return (
7
44
< div >
8
45
< h2 > React Universal App</ h2 >
46
+ < List />
9
47
</ div >
10
48
) ;
11
49
} ;
Original file line number Diff line number Diff line change 40
40
"esnext" : true ,
41
41
"space" : 2 ,
42
42
"globals" : [
43
- " document"
43
+ " document" ,
44
+ " fetch"
44
45
],
45
46
"extends" : [
46
47
" xo" ,
You can’t perform that action at this time.
0 commit comments