From 4212dae5bf048192a9256189d12370fa6f3c8680 Mon Sep 17 00:00:00 2001 From: Davenludd Date: Wed, 20 Mar 2024 13:53:58 +0100 Subject: [PATCH] Delete CountButton component --- frontend/src/Components/CountButton.tsx | 38 ------------------------- 1 file changed, 38 deletions(-) delete mode 100644 frontend/src/Components/CountButton.tsx diff --git a/frontend/src/Components/CountButton.tsx b/frontend/src/Components/CountButton.tsx deleted file mode 100644 index a6f1b30..0000000 --- a/frontend/src/Components/CountButton.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import { useState, useEffect } from "react"; - -// Interface for the response from the server -// This should eventually reside in a dedicated file -interface CountResponse { - pressCount: number; -} - -// Some constants for the button -const BUTTON_ENDPOINT = "/api/button"; - -// A simple button that counts how many times it's been pressed -export function CountButton(): JSX.Element { - const [count, setCount] = useState(NaN); - - // useEffect with a [] dependency array runs only once - useEffect(() => { - async function getCount(): Promise { - const response = await fetch(BUTTON_ENDPOINT); - const data = (await response.json()) as CountResponse; - setCount(data.pressCount); - } - void getCount(); - }, []); - - // This is what runs on every button click - function press(): void { - async function pressPost(): Promise { - const response = await fetch(BUTTON_ENDPOINT, { method: "POST" }); - const data = (await response.json()) as CountResponse; - setCount(data.pressCount); - } - void pressPost(); - } - - // Return some JSX with the button and associated handler - return ; -}