-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
67 lines (58 loc) · 1.86 KB
/
App.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
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
import React, { useState } from 'react'
import axios from 'axios'
function App() {
const [data, setData] = useState({})
const [location, setLocation] = useState('')
const url = `https://api.openweathermap.org/data/2.5/weather?q=${location}&units=imperial&appid=58e6d6b402f2dd68a1f578cad108584f`
const searchLocation = (event) => {
if (event.key === 'Enter') {
axios.get(url).then((response) => {
setData(response.data)
console.log(response.data)
})
setLocation('')
}
}
return (
<div className="app">
<div className="search">
<input
value={location}
onChange={event => setLocation(event.target.value)}
onKeyPress={searchLocation}
placeholder='Enter Location'
type="text" />
</div>
<div className="container">
<div className="top">
<div className="location">
<p>{data.name}</p>
</div>
<div className="temp">
{data.main ? <h1>{data.main.temp.toFixed()}°F</h1> : null}
</div>
<div className="description">
{data.weather ? <p>{data.weather[0].main}</p> : null}
</div>
</div>
{data.name !== undefined &&
<div className="bottom">
<div className="feels">
{data.main ? <p className='bold'>{data.main.feels_like.toFixed()}°F</p> : null}
<p>Feels Like</p>
</div>
<div className="humidity">
{data.main ? <p className='bold'>{data.main.humidity}%</p> : null}
<p>Humidity</p>
</div>
<div className="wind">
{data.wind ? <p className='bold'>{data.wind.speed.toFixed()} MPH</p> : null}
<p>Wind Speed</p>
</div>
</div>
}
</div>
</div>
);
}
export default App;