-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeatherInfo.html
More file actions
51 lines (51 loc) · 1.55 KB
/
WeatherInfo.html
File metadata and controls
51 lines (51 loc) · 1.55 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Finding Weather info</title>
</head>
<body>
<div id="WeatherInfo"></div>
<script src="https://fb.me/react-15.0.0.js"></script>
<script src="https://fb.me/react-dom-15.0.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
<script type="text/babel">
//Add extension to chrome " Allow-Control-Allow-Origin "
var WeatherInfo = React.createClass({
getInitialState: function() {
return { chicagoRes: '' };
},
componentDidMount: function(){
let chicagoUrl = 'http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b6907d289e10d714a6e88b30761fae22';
axios.get(chicagoUrl).then(res => {
if(res.status=='200'){
this.setState({chicagoRes : res.data});
}
});
},
render: function() {
const { chicagoRes } = this.state;
const { weather, name, wind } = chicagoRes || {};
return (
<div>
<h1>Weather Info Component</h1>
<div>
<b>Country : </b> {name}
</div>
<div>
<b>Weather : </b> {weather && weather[0].description }
</div>
<div>
<b>Wind Speed : </b> {wind && wind.speed }
</div>
</div>
)
}
});
ReactDOM.render(
<WeatherInfo/>,
document.getElementById('WeatherInfo')
);
</script>
</body>
</html>