Created
January 24, 2022 22:38
-
-
Save kuccello/5669b68cbb601327faf4dcfbf5cbe054 to your computer and use it in GitHub Desktop.
This file contains 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
// pages/index.tsx | |
// COPIED DIRECTLY FROM: https://keystonejs.com/docs/walkthroughs/embedded-mode-with-sqlite-nextjs | |
import { InferGetStaticPropsType } from 'next'; | |
import Link from 'next/link'; | |
// Import the generated Lists API and types from Keystone | |
import { query } from '.keystone/api'; | |
import { Lists } from '.keystone/types'; | |
type Post = { | |
id: string; | |
title: string; | |
slug: string; | |
}; | |
// Home receives a `posts` prop from `getStaticProps` below | |
export default function Home({ posts }: InferGetStaticPropsType<typeof getStaticProps>) { | |
return ( | |
<div> | |
<main style={{ margin: '3rem' }}> | |
<h1>Hello World! 👋🏻 </h1> | |
<ul> | |
{/* Render each post with a link to the content page */} | |
{posts.map(post => ( | |
<li key={post.id}> | |
<Link href={`/post/${post.slug}`}> | |
<a>{post.title}</a> | |
</Link> | |
</li> | |
))} | |
</ul> | |
</main> | |
</div> | |
); | |
} | |
// Here we use the Lists API to load all the posts we want to display | |
// The return of this function is provided to the `Home` component | |
export async function getStaticProps() { | |
const posts = await query.Post.findMany({ query: 'id title slug' }) as Post[]; | |
return { | |
props: { | |
posts | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment