Untitled
unknown
plain_text
a year ago
1.0 kB
1
Indexable
Never
async function fetchData() { try { const response = await axios.get( `https://api.openweathermap.org/data/2.5/weather?q=${location}&appid=${APIkey}` ); const data = response.data; setDataWeather(data); console.log(data.weather[0].main); } catch (error) { console.error("Error fetching data:", error); } } useEffect(() => { fetchData(); // Memanggil fungsi untuk mengambil data saat komponen dirender }, []); let icon; switch (data.weather[0].main) { case "Clouds": icon = <IoMdCloud />; break; case "Haze": icon = <BsFillCloudHaze2Fill />; break; case "Rain": icon = <IoMdRainy />; break; case "Clear": icon = <IoMdSunny />; break; case "Clear": icon = <BsCloudHazeFill />; break; case "Snow": icon = <IoMdSnow />; break; case "Thunderstrom": icon = <IoMdThunderstorm />; break; }