23 lines
578 B
TypeScript
23 lines
578 B
TypeScript
import Image from "next/image";
|
|
|
|
async function getData() {
|
|
const res = await fetch('https://my-json-server.typicode.com/typicode/demo/posts');
|
|
// 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();
|
|
return (
|
|
<main>
|
|
<p className = "text-lg font-sans hover:text-xl">{ data[ 1 ].title } </p>
|
|
</main>
|
|
);
|
|
}
|