Skip to content

Instantly share code, notes, and snippets.

@robbertvancaem
Created December 9, 2019 08:32
Show Gist options
  • Save robbertvancaem/9302adbc95bf5849f0545b22fc07184d to your computer and use it in GitHub Desktop.
Save robbertvancaem/9302adbc95bf5849f0545b22fc07184d to your computer and use it in GitHub Desktop.
dynamic-routing-now-8
// 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