export const getStaticPaths: GetStaticPaths = async () => {
const posts = await prisma.post.findMany();
// TODO: this can cause problems if we run this the first time the database is reset
if (posts) {
return {
paths: posts.map((post) => ({
params: {
id: post.id,
},
})),
fallback: false,
};
} else {
return {
paths: [],
fallback: false,
};
}
};
export const getStaticProps = async (
// this is the id from the page
context: GetStaticPropsContext<{ id: string }>
) => {
const ssg = createProxySSGHelpers({
router: appRouter,
transformer: superjson,
ctx: await createContextInner({ session: null }),
});
await ssg.post.getAllPosts.prefetch();
return {
props: {
trpcState: ssg.dehydrate(),
id: context.params?.id,
},
revalidate: 1,
};
};
export const getStaticPaths: GetStaticPaths = async () => {
const posts = await prisma.post.findMany();
// TODO: this can cause problems if we run this the first time the database is reset
if (posts) {
return {
paths: posts.map((post) => ({
params: {
id: post.id,
},
})),
fallback: false,
};
} else {
return {
paths: [],
fallback: false,
};
}
};
export const getStaticProps = async (
// this is the id from the page
context: GetStaticPropsContext<{ id: string }>
) => {
const ssg = createProxySSGHelpers({
router: appRouter,
transformer: superjson,
ctx: await createContextInner({ session: null }),
});
await ssg.post.getAllPosts.prefetch();
return {
props: {
trpcState: ssg.dehydrate(),
id: context.params?.id,
},
revalidate: 1,
};
};