App.js
1.32 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React, { Component } from 'react';
import './App.css';
import axios from 'axios';
import ReactSpinner from 'react-spinjs';
import Header from './Components/Header';
class App extends Component {
constructor(props){
super(props);
this.state = {
shorten : undefined
};
this.fetchShorten = this.fetchShorten.bind(this);
this.printShorten = this.printShorten.bind(this);
}
componentDidMount(){
this.fetchShorten();
}
fetchShorten() {
var URL = 'http://localhost:4000';
return axios.get(URL)
.then((response) => {
console.log(response);
this.setState({
shorten : response.data.shorten
});
})
.catch((error) => {
this.setState({
shorten : error
});
});
}
printShorten() {
if(this.state.shorten){
return (
<div className="shorten">
<p>1 : {this.state.shorten[0]}</p>
<p>2 : {this.state.shorten[1]}</p>
<p>3 : {this.state.shorten[2]}</p>
</div>
);
} else {
return (
<div>
<ReactSpinner top="50%" left="50%"/>
</div>
);
}
}
render() {
return (
<div className="App">
<Header />
<div className="App-intro">
{this.printShorten()}
</div>
</div>
);
}
}
export default App;