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

Commit d2b3ce4

Browse files
committed
use getInitialProps for chapter page
1 parent 4f88e17 commit d2b3ce4

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

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

Lines changed: 10 additions & 12 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 Error from 'next/error';
33
import { Container, Grid } from '@material-ui/core';
44
import ChapterDetails from '@zoonk/components/ChapterDetails';
@@ -7,22 +7,13 @@ import Meta from '@zoonk/components/Meta';
77
import TopicsBreadcrumb from '@zoonk/components/TopicsBreadcrumb';
88
import { Chapter } from '@zoonk/models';
99
import { getChapter } from '@zoonk/services';
10+
import { preRender } from '@zoonk/utils';
1011

1112
interface ChapterProps {
1213
data: Chapter.Get | null;
1314
}
1415

15-
export const getServerSideProps: GetServerSideProps<ChapterProps> = async ({
16-
params,
17-
}) => {
18-
const id = String(params?.id);
19-
const data = await getChapter(id);
20-
return { props: { data } };
21-
};
22-
23-
const ChapterPage = ({
24-
data,
25-
}: InferGetServerSidePropsType<typeof getServerSideProps>) => {
16+
const ChapterPage: NextPage<ChapterProps> = ({ data }) => {
2617
if (!data) return <Error statusCode={404} />;
2718

2819
const {
@@ -70,4 +61,11 @@ const ChapterPage = ({
7061
);
7162
};
7263

64+
ChapterPage.getInitialProps = async ({ query }) => {
65+
const id = String(query.id);
66+
const data = await getChapter(id);
67+
preRender();
68+
return { data };
69+
};
70+
7371
export default ChapterPage;

0 commit comments

Comments
 (0)