Skip to content

Commit

Permalink
fix lost data when reload
Browse files Browse the repository at this point in the history
  • Loading branch information
phucprime committed Aug 10, 2021
1 parent ac36998 commit 53dfcb0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ import styles from "../styles/Home.module.css";
import Image from "next/image";

export default function Home() {

const [input, setInput] = useState("Ho Chi Minh");
const [systemUsed, setSystemUsed] = useState("metric");
const [weatherData, setWeatherData] = useState();

useEffect(() => {
getData();
}, []);

const getData = 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("");
// setInput("");
};

const enterKeydown = (event) => {
Expand All @@ -25,10 +29,7 @@ export default function Home() {
}
};

useEffect(() => {
getData();
}, []);

// cal wind direction
function degToCompass(num) {
var val = Math.floor(num / 22.5 + 0.5);
var arr = [
Expand Down Expand Up @@ -56,7 +57,6 @@ export default function Home() {
const time = new Date((unixSeconds + timezone) * 1000)
.toISOString()
.match(/(\d{2}:\d{2})/);

return time;
};

Expand Down

0 comments on commit 53dfcb0

Please sign in to comment.