Skip to content
This repository was archived by the owner on Jun 28, 2025. It is now read-only.

Commit 44b7f79

Browse files
author
Manuel Proß
committed
feat(web): add swr
1 parent 80e7f71 commit 44b7f79

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

web/src/app/page.tsx

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
11
"use client";
22
import { useEffect, useState } from "react";
3+
import useSWR from "swr";
34
import Hero from "@/components/Strapi/Sections/HeroSection";
45
import PageContent from "@/components/Strapi/Sections/Content";
56
import { PageAttributes } from "@/types/strapi";
67

7-
export default function Home() {
8-
const [pageData, setPageData] = useState<PageAttributes | undefined>(undefined);
9-
10-
useEffect(() => {
11-
const fetchData = async () => {
12-
const res = await fetch(`/api/homepage`);
13-
if (!res.ok) {
14-
throw new Error("fetching homepage hero failed");
15-
}
8+
const fetcher = (url: string) => fetch(url).then(res => res.json() as Promise<PageAttributes>);
169

17-
const data = (await res.json()) as PageAttributes;
18-
setPageData(data);
19-
};
20-
21-
fetchData();
22-
}, []);
10+
export default function Home() {
11+
// const [pageData, setPageData] = useState<PageAttributes | undefined>(undefined);
12+
const { data } = useSWR("/api/homepage", fetcher);
2313

2414
return (
25-
<main className="pb-12">
26-
{pageData && (
2715
<main className="relative z-1 pb-12">
16+
{data && (
2817
<>
29-
<Hero headline={pageData.Hero.headline} list={pageData.Hero.list} cta={pageData.Hero.cta} />
30-
<PageContent entries={pageData.body} />
18+
<Hero headline={data.Hero.headline} list={data.Hero.list} cta={data.Hero.cta} />
19+
<PageContent entries={data.body} />
3120
</>
3221
)}
3322
</main>

0 commit comments

Comments
 (0)