-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoading-Spinner-Example.js
57 lines (54 loc) · 1.36 KB
/
Loading-Spinner-Example.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
56
57
// LoaderComponent.js
import React, { Component } from 'react';
import axios from 'axios';
export default class LoaderComponent extends Component {
constructor(props) {
super(props);
this.state = this.state = {
name:'',
company:'',
blog: '',
avatar:'',
loading: false
}
}
componentDidMount()
{
axios.get("https://api.github.com/users/georgioupanayiotis")
.then(response => {
this.setState({
name:response.data.name,
company:response.data.company,
blog: response.data.blog,
avatar:response.data.avatar_url,
loading: false
});
})
.catch(error => {
console.log(error);
});
}
render()
{
let data;
if (this.state.loading) {
data = <img src={ require('https://media.giphy.com/media/3oEjI6SIIHBdRxXI40/giphy.gif') } />
} else {
data = <div>
<br/>
Name: {this.state.name}
<br/>
Company: {this.state.company}
<br/>
Blog: {this.state.blog}
<br/>
<img src={this.state.avatar}/>
</div>
}
return(
<div>
{data}
</div>
)
}
}