mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
9c4eefcdbf
* Add prettier for examples directory * Fix files * Fix linting * Add prettier script in case it has to be ran again
34 lines
706 B
JavaScript
34 lines
706 B
JavaScript
import { Component } from 'react'
|
|
import Link from 'next/link'
|
|
import Head from 'next/head'
|
|
import fetch from 'isomorphic-unfetch'
|
|
|
|
export default class extends Component {
|
|
static async getInitialProps ({ query }) {
|
|
// fetch single post detail
|
|
const response = await fetch(
|
|
`https://jsonplaceholder.typicode.com/posts/${query.id}`
|
|
)
|
|
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>
|
|
)
|
|
}
|
|
}
|