From 66fb96acbade91cddcbe42429aca12d961aba639 Mon Sep 17 00:00:00 2001 From: Nils <1059147@bkrnet.de> Date: Tue, 16 Jan 2024 13:43:56 +0100 Subject: [PATCH] Update response object in API handler --- src/app/dashboard/page.tsx | 23 +++++++++++++---------- src/pages/api/hello.ts | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index 72907fa..6e71882 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -36,21 +36,24 @@ const columns: GridColDef[] = [ ]; -const URL= "http://100.101.64.38:3000/api/hello"; +const URL = "http://100.101.64.38:3000/api/hello"; export default function Page() { + const [data, setData] = useState({ mes: "" }); - - - const [data, setData] = useState([]); - useEffect(() => { - async function getData() { + useEffect(() => { + async function getData() { + try { const response = await fetch(URL); - const data = await response.json(); - setData(data); + const jsonData = await response.json(); + setData(jsonData); + } catch (error) { + console.error("Error fetching data:", error); } - getData(); - }, []) + } + + getData(); + }, []); const rows = [ diff --git a/src/pages/api/hello.ts b/src/pages/api/hello.ts index aef2a60..bf4edb1 100644 --- a/src/pages/api/hello.ts +++ b/src/pages/api/hello.ts @@ -8,5 +8,5 @@ export default function handler( req: NextApiRequest, res: NextApiResponse ) { - res.status(200).send({ Vorname: 'test' }) + res.status(200).send({ message: 'test' }) }