Created
December 9, 2019 08:32
-
-
Save robbertvancaem/9302adbc95bf5849f0545b22fc07184d to your computer and use it in GitHub Desktop.
dynamic-routing-now-8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pages/post.js | |
import React from 'react'; | |
import withError from '../hoc/withError'; | |
import { getPost } from '../data/posts'; | |
const Post = ({ post }) => { | |
const { title: { rendered: title }, slug } = post; | |
return ( | |
<div> | |
<h1>{title}</h1> | |
<p>{slug}</p> | |
</div> | |
); | |
} | |
Post.getInitialProps = async (slug) => { | |
const { statusCode, post } = await getPost(slug); | |
return { | |
statusCode, | |
post, | |
} | |
} | |
export default withError(Post); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment