graphql-engine/community/sample-apps/nextjs-incremental-static-regeneration/pages/index.tsx
hasura-bot 810c94c776 community: add nextjs-incremental-static-regeneration
GITHUB_PR_NUMBER: 8320
GITHUB_PR_URL: https://github.com/hasura/graphql-engine/pull/8320

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3976
Co-authored-by: arjunyel <11153289+arjunyel@users.noreply.github.com>
GitOrigin-RevId: a3d8f705900c814a3f2017b239b86960943c8677
2022-03-17 11:53:17 +00:00

48 lines
719 B
TypeScript

import type { NextPage } from "next";
import { request, gql } from "graphql-request";
interface Props {
posts: {
id: string;
title: string;
content: string;
}[];
}
const query = gql`
{
post {
content
id
title
}
}
`;
export async function getStaticProps() {
const { post: posts } = await request(
"http://localhost:8080/v1/graphql",
query
);
return {
props: {
posts,
},
};
}
const Home: NextPage<Props> = ({ posts }) => {
return (
<main>
{posts.map((post) => (
<article key={post.id}>
<h2>{post.title}</h2>
<p>{post.content}</p>
</article>
))}
</main>
);
};
export default Home;