import { useState } from "react";
import "./main.css"
function Main() {
let API_KEY = "f621742c67e9f1c2440126216a490708";
let [city, setCity] = useState("");
let getWeather = async (e) => {
e.preventDefault();
let api_url = await
fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${API_KEY}&units=metric`)
const data = await api_url.json()
return data;
}
return (
< >
<form>
<div><h2 className="main_info">Weather information</h2></div>
<input className="input" value={city} onChange={e=>setCity(e.target.value)} type="text" placeholder="Название города"/>
<button className="btn" onClick={getWeather}>Получить данные</button>
<p>{data.name}</p>
<p>{data.tittle}</p>
</form>
</>
);
}
export default Main;
const [data, setData] = useState({});
const getWeather = () => fetch("ваша ссылка", {method: "GET"}).then((response) => {обрабатываем статус коды})
.then(result => setData(result)).catch(e => console.erreoe(e));