rsnext/examples/with-static-export/pages/index.js
2020-05-18 15:24:37 -04:00

34 lines
626 B
JavaScript

import Head from 'next/head'
import Post from '../components/post'
export async function getStaticProps() {
// fetch list of posts
const response = await fetch(
'https://jsonplaceholder.typicode.com/posts?_page=1'
)
const postList = await response.json()
return {
props: {
postList,
},
}
}
export default function IndexPage({ postList }) {
return (
<main>
<Head>
<title>Home page</title>
</Head>
<h1>List of posts</h1>
<section>
{postList.map((post) => (
<Post {...post} key={post.id} />
))}
</section>
</main>
)
}