Created
April 11, 2024 09:35
-
-
Save erasebegin/d35c99cc7fe621198f60259eed69936e to your computer and use it in GitHub Desktop.
Example of Hygraph in Next 14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Suspense } from "react"; | |
import MaterialsSections from "./components/MaterialsSections"; | |
import PageHeader from "./components/PageHeader"; | |
import { Loader2 } from "lucide-react"; | |
export default async function Home() { | |
const { errors, data } = await fetch(process.env.HYGRAPH_URL as string, { | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json", | |
}, | |
body: JSON.stringify({ | |
query: ` | |
{ | |
sessions(first: 100) { | |
duration | |
id | |
publishedAt | |
title | |
updatedAt | |
language | |
sessionMaterials { | |
canvaLink | |
file { | |
url | |
mimeType | |
} | |
title | |
id | |
} | |
promotionalMaterials { | |
canvaLink | |
file { | |
url | |
mimeType | |
} | |
title | |
id | |
} | |
} | |
} | |
`, | |
}), | |
}).then((res) => res.json()); | |
if (errors) { | |
console.error(errors); | |
return <div className="p10">Error fetching data</div>; | |
} | |
return ( | |
<main className="flex min-h-screen flex-col items-center px-3 md:px-10"> | |
<PageHeader page="materials" /> | |
<Suspense | |
fallback={<Loader2 className="animate-spin text-brown-200 size-8" />} | |
> | |
<MaterialsSections sessionData={data.sessions} /> | |
</Suspense> | |
</main> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment