rsnext/examples/with-static-export/pages/post/[id].js

36 lines
713 B
JavaScript
Raw Normal View History

2017-07-01 21:44:58 +02:00
import { Component } from 'react'
import Link from 'next/link'
import Head from 'next/head'
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
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 () {
const { title, body } = this.props
2017-07-01 21:44:58 +02:00
return (
<main>
<Head>
<title>{title}</title>
2017-07-01 21:44:58 +02:00
</Head>
<h1>{title}</h1>
2017-07-01 21:44:58 +02:00
<p>{body}</p>
2017-07-01 21:44:58 +02:00
<Link href='/'>
<a>Go back to home</a>
</Link>
</main>
)
}
}