Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit bfc7d29

Browse files
committed
use getInitialProps for post page
1 parent aa5779d commit bfc7d29

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/pages/posts/[id]/index.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GetServerSideProps, InferGetServerSidePropsType } from 'next';
1+
import { NextPage } from 'next';
22
import dynamic from 'next/dynamic';
33
import Error from 'next/error';
44
import { Container, Divider, makeStyles } from '@material-ui/core';
@@ -11,7 +11,7 @@ import RichTextViewer from '@zoonk/components/rich-text/RichTextViewer';
1111
import { getPlainText, getPostImage } from '@zoonk/components/rich-text/posts';
1212
import { Post } from '@zoonk/models';
1313
import { getPost } from '@zoonk/services';
14-
import { appLanguage, PostContext } from '@zoonk/utils';
14+
import { appLanguage, PostContext, preRender } from '@zoonk/utils';
1515

1616
const 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+
8178
export default PostPage;

0 commit comments

Comments
 (0)