next-app/app/page.tsx
Alex Stan e2955ef5bb Use our own API instead of the test one
Signed-off-by: Alex Stan <alex.stan.2010@proton.me>
2024-06-01 11:21:45 +03:00

25 lines
621 B
TypeScript

import Image from "next/image";
async function getData( url: string ) {
const res = await fetch( url );
// The return value is *not* serialized
// You can return Date, Map, Set, etc.
if (!res.ok) {
// This will activate the closest `error.js` Error Boundary
throw new Error('Failed to fetch data');
}
return res.json()
}
export default async function Home() {
const data = await getData( "http://localhost:4000/questions" );
return (
<main>
{ data.map( (item: any) => (
<p className = "text-lg font-sans hover:text-xl">{ item.question } </p>
) ) }
</main>
);
}