arbret/frontend/app/page.tsx

41 lines
941 B
TypeScript
Raw Normal View History

2025-12-18 21:37:28 +01:00
"use client";
import { useEffect, useState } from "react";
export default function Home() {
2025-12-18 21:48:41 +01:00
const [count, setCount] = useState<number | null>(null);
2025-12-18 21:37:28 +01:00
useEffect(() => {
2025-12-18 21:48:41 +01:00
fetch("http://localhost:8000/api/counter")
2025-12-18 21:37:28 +01:00
.then((res) => res.json())
2025-12-18 21:48:41 +01:00
.then((data) => setCount(data.value));
2025-12-18 21:37:28 +01:00
}, []);
2025-12-18 21:48:41 +01:00
const increment = async () => {
const res = await fetch("http://localhost:8000/api/counter/increment", {
method: "POST",
});
const data = await res.json();
setCount(data.value);
};
2025-12-18 21:37:28 +01:00
return (
2025-12-18 21:48:41 +01:00
<main style={{ padding: "2rem", fontFamily: "system-ui", textAlign: "center" }}>
<h1 style={{ fontSize: "6rem", margin: "2rem 0" }}>
{count === null ? "..." : count}
</h1>
<button
onClick={increment}
style={{
fontSize: "1.5rem",
padding: "1rem 2rem",
cursor: "pointer",
}}
>
+1
</button>
2025-12-18 21:37:28 +01:00
</main>
);
}