2017-07-01 19:44:58 +00:00
|
|
|
import { Component } from 'react'
|
|
|
|
import Link from 'next/link'
|
|
|
|
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
|
|
|
|
|
|
|
export default class extends Component {
|
|
|
|
static async getInitialProps ({ query }) {
|
|
|
|
// fetch single post detail
|
2018-12-17 16:34:32 +00:00
|
|
|
const response = await fetch(
|
|
|
|
`https://jsonplaceholder.typicode.com/posts/${query.id}`
|
|
|
|
)
|
2017-07-01 19:44:58 +00:00
|
|
|
const post = await response.json()
|
|
|
|
return { ...post }
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<main>
|
|
|
|
<Head>
|
|
|
|
<title>{this.props.title}</title>
|
|
|
|
</Head>
|
|
|
|
|
|
|
|
<h1>{this.props.title}</h1>
|
|
|
|
|
|
|
|
<p>{this.props.body}</p>
|
|
|
|
|
|
|
|
<Link href='/'>
|
|
|
|
<a>Go back to home</a>
|
|
|
|
</Link>
|
|
|
|
</main>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|