next-app/app/page.tsx
Alex Stan 7ee284084f Get posts from API
Signed-off-by: Alex Stan <alex.stan.2010@proton.me>
2024-06-01 11:06:08 +03:00

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>
);
}