-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
41 lines (34 loc) · 793 Bytes
/
App.js
File metadata and controls
41 lines (34 loc) · 793 Bytes
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
import React from 'react';
import axios from 'axios';
import './App.css';
class App extends React.Component {
state = {
advice: '',
}
componentDidMount() {
this.fetchAdvice();
}
fetchAdvice = () => {
axios.get('https://api.adviceslip.com/advice')
.then((response) => {
const { advice } = response.data.slip;
this.setState({ advice });
})
.catch((error) => {
console.log(error);
});
}
render() {
return (
<div className="app">
<div className="card">
<h1 className="heading">{this.state.advice}</h1>
<button className="button" onClick={this.fetchAdvice}>
<span>GIVE ME ADVICE!</span>
</button>
</div>
</div>
);
}
}
export default App;