-
Notifications
You must be signed in to change notification settings - Fork 0
/
Home.js
37 lines (34 loc) · 902 Bytes
/
Home.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
import React, { Component } from 'react';
import auth from './auth';
export class Home extends Component {
constructor(props) {
super(props);
this.state = {};
}
fetchWeather() {
auth.getToken().then(accessToken => {
fetch("/weatherforecast", { headers: { Authorization: `Bearer ${accessToken}` } }).then(response => {
response.json().then(result => {
this.setState(result);
})
});
});
}
render() {
const weather = this.state && this.state[0] ? this.state[0] : undefined;
return (
<div>
<h1>Tomorrow's weather forecast</h1>
<br />
<button onClick={() => this.fetchWeather()}>refresh</button>
<br />
{weather &&
<div>
<p>Temperature: {weather.temperatureC}</p>
<p>Sumnmary: {weather.summary}</p>
</div>
}
</div>
);
}
}