-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
90 lines (74 loc) · 1.95 KB
/
test
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
return (
<img
src={search_icon}
alt=""
onClick={() => search(inputRef.current.value)}
/>
);
const MyComponent = () => {
const inputRef = useRef();
const search = (value) => {
if(city === ""){
alert("Please Enter A Valid City.")
return;
}
try {
const url = `https://api.openweathermap.org/data/2.5/weather?q=${city}&units=imperial&appid=${import.meta.env.VITE_APP_ID}`;
const response = fetch(url);
const data = response.json();
console.log(data);
const icon = allIcons[data.weather[0].icon] || clear_icon
setWeatherData ({
humidity: data.main.humidity,
windSpeed: data.wind.speed,
temperature: Math.floor(data.main.temp),
location: data.name,
icon: icon
})
} catch (error) {
console.log(error)
}
}
};
useEffect(()=>{
search("London");
}, [])
return (
<div className='weather'>
<div className="search-bar">
<input ref={inputRef} type="text" placeholder='Search' />
return (
<img
src={search_icon}
alt=""
onClick={() => search(inputRef.current.value)}
/>
);
</div>
<img src={clear_icon} alt="" className='weather_icon' />
<p className='temperature'>{weatherData.temperature} °F</p>
<p className='location'>{weatherData.location}</p>
<div className="weather-data">
<div className="col">
<img src={humidity_icon} alt="" />
<div>
<p>{weatherData.humidity} %</p>
<span>Humidity</span>
</div>
</div>
<div className="col">
<img src={wind_icon} alt="" />
<div>
<p>{weatherData.windSpeed} MPH</p>
<span>Wind Speed</span>
</div>
</div>
</div>
</div>
)
// }
// Test number 3
// const MyComponent = () => {
// const inputRef = useRef();
// const search = (value) => {
// };