App.js
1.26 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
import React, { Component } from 'react';
import logo from './logo.png';
import './App.css';
import axios from 'axios';
class App extends Component {
constructor(props){
super(props);
this.state = {
shorten : []
};
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>
<p>1 : {this.state.shorten[0]}</p>
<p>2 : {this.state.shorten[1]}</p>
<p>3 : {this.state.shorten[2]}</p>
</div>
);
}
}
render() {
return (
<div className="App">
<div className="App-header">
<img src={logo} className="App-logo" alt="logo"/>
<h2>Redesigned by 3Line</h2>
</div>
<div className="App-intro">
{this.printShorten()}
</div>
</div>
);
}
}
export default App;