2017-07-01 19:44:58 +00:00
|
|
|
import { Component } from 'react'
|
|
|
|
import Head from 'next/head'
|
2017-11-04 14:05:16 +00:00
|
|
|
import fetch from 'isomorphic-unfetch'
|
2017-07-01 19:44:58 +00:00
|
|
|
|
|
|
|
import Post from '../components/post'
|
|
|
|
|
|
|
|
export default class extends Component {
|
|
|
|
static async getInitialProps () {
|
|
|
|
// fetch list of posts
|
2017-09-01 06:24:03 +00:00
|
|
|
const response = await fetch('https://jsonplaceholder.typicode.com/posts?_page=1')
|
2017-07-01 19:44:58 +00:00
|
|
|
const postList = await response.json()
|
|
|
|
return { postList }
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<main>
|
|
|
|
<Head>
|
|
|
|
<title>Home page</title>
|
|
|
|
</Head>
|
|
|
|
|
|
|
|
<h1>List of posts</h1>
|
|
|
|
|
|
|
|
<section>
|
|
|
|
{this.props.postList.map(post => <Post {...post} key={post.id} />)}
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|