2017-07-01 21:44:58 +02:00
|
|
|
import { Component } from 'react'
|
|
|
|
import Link from 'next/link'
|
|
|
|
import Head from 'next/head'
|
2017-11-04 15:05:16 +01:00
|
|
|
import fetch from 'isomorphic-unfetch'
|
2017-07-01 21:44:58 +02:00
|
|
|
|
|
|
|
export default class extends Component {
|
|
|
|
static async getInitialProps ({ query }) {
|
|
|
|
// fetch single post detail
|
2018-12-17 17:34:32 +01:00
|
|
|
const response = await fetch(
|
|
|
|
`https://jsonplaceholder.typicode.com/posts/${query.id}`
|
|
|
|
)
|
2017-07-01 21:44:58 +02:00
|
|
|
const post = await response.json()
|
|
|
|
return { ...post }
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2019-10-29 17:17:48 +01:00
|
|
|
const { title, body } = this.props
|
|
|
|
|
2017-07-01 21:44:58 +02:00
|
|
|
return (
|
|
|
|
<main>
|
|
|
|
<Head>
|
2019-10-29 17:17:48 +01:00
|
|
|
<title>{title}</title>
|
2017-07-01 21:44:58 +02:00
|
|
|
</Head>
|
|
|
|
|
2019-10-29 17:17:48 +01:00
|
|
|
<h1>{title}</h1>
|
2017-07-01 21:44:58 +02:00
|
|
|
|
2019-10-29 17:17:48 +01:00
|
|
|
<p>{body}</p>
|
2017-07-01 21:44:58 +02:00
|
|
|
|
|
|
|
<Link href='/'>
|
|
|
|
<a>Go back to home</a>
|
|
|
|
</Link>
|
|
|
|
</main>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|