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

Commit 4f88e17

Browse files
committed
use getInitialProps for group page
1 parent bfc7d29 commit 4f88e17

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

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

Lines changed: 12 additions & 16 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 } from '@material-ui/core';
44
import GroupBase from '@zoonk/components/GroupBase';
@@ -9,7 +9,7 @@ import PostShare from '@zoonk/components/PostShare';
99
import PostsList from '@zoonk/components/PostsList';
1010
import { Group, Post } from '@zoonk/models';
1111
import { getGroup, getPosts } from '@zoonk/services';
12-
import { appLanguage } from '@zoonk/utils';
12+
import { appLanguage, preRender } from '@zoonk/utils';
1313

1414
interface GroupPageProps {
1515
group: Group.Get | null;
@@ -18,20 +18,7 @@ interface GroupPageProps {
1818

1919
const limit = 10;
2020

21-
export const getServerSideProps: GetServerSideProps<GroupPageProps> = async ({
22-
params,
23-
}) => {
24-
const groupId = String(params?.id);
25-
const groupReq = getGroup(groupId);
26-
const postsReq = getPosts({ groupId, limit });
27-
const [group, posts] = await Promise.all([groupReq, postsReq]);
28-
return { props: { group, posts } };
29-
};
30-
31-
const GroupPage = ({
32-
group,
33-
posts,
34-
}: InferGetServerSidePropsType<typeof getServerSideProps>) => {
21+
const GroupPage: NextPage<GroupPageProps> = ({ group, posts }) => {
3522
if (!group) return <Error statusCode={404} />;
3623

3724
const { description, id, language, photo, title, topics } = group;
@@ -56,4 +43,13 @@ const GroupPage = ({
5643
);
5744
};
5845

46+
GroupPage.getInitialProps = async ({ query }) => {
47+
const groupId = String(query.id);
48+
const groupReq = getGroup(groupId);
49+
const postsReq = getPosts({ groupId, limit });
50+
const [group, posts] = await Promise.all([groupReq, postsReq]);
51+
preRender();
52+
return { group, posts };
53+
};
54+
5955
export default GroupPage;

0 commit comments

Comments
 (0)