import { useState, useEffect } from "react"; import styles from "../styles/Home.module.css"; import Image from "next/image"; export default function Home() { const [input, setInput] = useState(); const [weatherData, setWeatherData] = useState(); const clickHandler = async () => { const res = await fetch("/api/data", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ input }), }); const data = await res.json(); setWeatherData({ ...data }); setInput(""); }; const something = (event) => { if (event.keyCode === 13) { clickHandler(); } }; return (
{weatherData.weather[0].description}
Feels like {Math.round(weatherData.main.feels_like)}°
> )} (e.target.value = "")} onChange={(e) => setInput(e.target.value)} onKeyDown={(e) => something(e)} />