25 lines
621 B
TypeScript
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>
|
|
);
|
|
}
|