From 8281d66939b37d57122c93fe0ab44ceebf941372 Mon Sep 17 00:00:00 2001 From: Alex Stan Date: Sat, 1 Jun 2024 11:08:49 +0300 Subject: [PATCH] Get posts from API (#2) Co-authored-by: Alex Stan Co-committed-by: Alex Stan --- .nvmrc | 1 + app/page.tsx | 124 +++++++-------------------------------------------- 2 files changed, 18 insertions(+), 107 deletions(-) create mode 100644 .nvmrc diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..a81deba --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v20.12.2 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 -

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

); }