This repository was archived by the owner on Jun 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +8
-19
lines changed Expand file tree Collapse file tree 1 file changed +8
-19
lines changed Original file line number Diff line number Diff line change 1
1
"use client" ;
2
2
import { useEffect , useState } from "react" ;
3
+ import useSWR from "swr" ;
3
4
import Hero from "@/components/Strapi/Sections/HeroSection" ;
4
5
import PageContent from "@/components/Strapi/Sections/Content" ;
5
6
import { PageAttributes } from "@/types/strapi" ;
6
7
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 > ) ;
16
9
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 ) ;
23
13
24
14
return (
25
- < main className = "pb-12" >
26
- { pageData && (
27
15
< main className = "relative z-1 pb-12" >
16
+ { data && (
28
17
< >
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 } />
31
20
</ >
32
21
) }
33
22
</ main >
You can’t perform that action at this time.
0 commit comments