I have file in this path ./pages/blog/[id]/[title].js and here are the codes that I have written :
import React from 'react';
import PropTypes from 'prop-types';
import fetch from 'isomorphic-unfetch';
import BASE_URL from '../../../BaseURL';
const BlogSinglePage = props => {
console.log(props.post);//undefined
console.log(props);//{}
return (
<div></div>
);
};
BlogSinglePage.propTypes = {
post: PropTypes.object
};
BlogSinglePage.getInitialProps = async ({ query }) => {
const res = await fetch(`${BASE_URL}/api/post/${query.id}`);
const post = await res.json();
return { post };
};
export default BlogSinglePage;
my problem is when getInitialProps is an async function , BlogSinglePage 's props is empty but whenever getInitialProps is not an async function , everything works and props is not empty
I have followed the code in Implement the Post Page line by line but it's not working for me