Skip to content

Commit cf52bc8

Browse files
committed
Improve type safety for dynamically imported MDX content in blog pages
1 parent 29588fe commit cf52bc8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/app/blog/[slug]/page.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getBlogPosts } from '@/content/utils';
44
import { baseUrl } from '@/app/sitemap';
55
import { customComponents } from '@/mdx-components';
66
import ClientDate from '@/app/components/client-date';
7+
import { ComponentType } from 'react';
78

89
type BlogPostPageProps = {
910
params: Promise<{
@@ -70,8 +71,12 @@ export default async function BlogPostPage({ params }: BlogPostPageProps) {
7071
}
7172

7273
// Import the MDX content dynamically
73-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
74-
const MDXContent = await import(`@/content/blog/${slug}.mdx`);
74+
const { default: MDXContent } = (await import(
75+
`@/content/blog/${slug}.mdx`
76+
)) as {
77+
default: ComponentType;
78+
};
79+
7580
return (
7681
<div className="container mx-auto py-8">
7782
<article className="prose prose-lg dark:prose-invert mx-auto">
@@ -93,7 +98,7 @@ export default async function BlogPostPage({ params }: BlogPostPageProps) {
9398
</span>
9499
</span>
95100
</p>
96-
<MDXContent.default />
101+
<MDXContent />
97102
</article>
98103
</div>
99104
);

0 commit comments

Comments
 (0)