-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserList.js
More file actions
48 lines (41 loc) · 1.24 KB
/
UserList.js
File metadata and controls
48 lines (41 loc) · 1.24 KB
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
import React, {Component} from 'react';
import {Link} from 'react-router-dom';
const GITHUB_USER_LIST_API = 'https://api.github.com/users?since=135';
class UserList extends Component {
constructor(props){
super(props)
this.state = {
userList: [],
isFetching: false
}
}
async componentDidMount(){
this.setState({isFetching: true})
const res = await fetch(GITHUB_USER_LIST_API)
const userList = await res.json()
this.setState({userList, isFetching: false})
}
render(){
if(this.state.isFetching){
return(
<div>
<h1>Fetching user list, Please wait...</h1>
</div>
)
}
return(
<div>
<ul style={{textAlign: 'left'}}>
{this.state.userList.map(user=>(
<li key={user.id}>
<Link to={`/user/${user.login}`}>
{user.login}
</Link>
</li>
))}
</ul>
</div>
)
}
}
export default UserList