From 7ee284084f7235ac6bdc838a62b3ddba1ba9029f Mon Sep 17 00:00:00 2001 From: Alex Stan Date: Sat, 1 Jun 2024 11:06:08 +0300 Subject: [PATCH] Get posts from API Signed-off-by: Alex Stan --- app/page.tsx | 124 +++++++-------------------------------------------- 1 file changed, 17 insertions(+), 107 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 5705d4e..e84cac1 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,113 +1,23 @@ import Image from "next/image"; -export default function Home() { +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 ( -
-
-

- Get started by editing  - app/page.tsx -

-
- - By{" "} - Vercel Logo - -
-
- -
- Next.js Logo -
- -
- -

- Docs{" "} - - -> - -

-

- Find in-depth information about Next.js features and API. -

-
- - -

- Learn{" "} - - -> - -

-

- Learn about Next.js in an interactive course with quizzes! -

-
- - -

- Templates{" "} - - -> - -

-

- Explore starter templates for Next.js. -

-
- - -

- Deploy{" "} - - -> - -

-

- Instantly deploy your Next.js site to a shareable URL with Vercel. -

-
-
+
+

{ data[ 1 ].title }

); }