1- import { GetServerSideProps , InferGetServerSidePropsType } from 'next' ;
1+ import { NextPage } from 'next' ;
22import dynamic from 'next/dynamic' ;
33import Error from 'next/error' ;
44import { Container , Divider , makeStyles } from '@material-ui/core' ;
@@ -11,7 +11,7 @@ import RichTextViewer from '@zoonk/components/rich-text/RichTextViewer';
1111import { getPlainText , getPostImage } from '@zoonk/components/rich-text/posts' ;
1212import { Post } from '@zoonk/models' ;
1313import { getPost } from '@zoonk/services' ;
14- import { appLanguage , PostContext } from '@zoonk/utils' ;
14+ import { appLanguage , PostContext , preRender } from '@zoonk/utils' ;
1515
1616const CommentList = dynamic ( ( ) => import ( '@zoonk/components/CommentList' ) , {
1717 ssr : false ,
@@ -34,17 +34,7 @@ const useStyles = makeStyles((theme) => ({
3434 } ,
3535} ) ) ;
3636
37- export const getServerSideProps : GetServerSideProps < PostPageProps > = async ( {
38- params,
39- } ) => {
40- const id = String ( params ?. id ) ;
41- const data = await getPost ( id ) ;
42- return { props : { data } } ;
43- } ;
44-
45- const PostPage = ( {
46- data,
47- } : InferGetServerSidePropsType < typeof getServerSideProps > ) => {
37+ const PostPage : NextPage < PostPageProps > = ( { data } ) => {
4838 const classes = useStyles ( ) ;
4939
5040 if ( ! data ) return < Error statusCode = { 404 } /> ;
@@ -78,4 +68,11 @@ const PostPage = ({
7868 ) ;
7969} ;
8070
71+ PostPage . getInitialProps = async ( { query } ) => {
72+ const id = String ( query . id ) ;
73+ const data = await getPost ( id ) ;
74+ preRender ( ) ;
75+ return { data } ;
76+ } ;
77+
8178export default PostPage ;
0 commit comments