#Next mdx remote in rsc
1 messages · Page 1 of 1 (latest)
What is your code? A simplified version that is
Ah nvm
If the layout is a client component
I deleted layout
The page becomes a client component as well
Well i need a simplified version of your code then
Okay
import { serialize } from 'next-mdx-remote/serialize'
import { MDXRemote } from 'next-mdx-remote'
export async function generateStaticParams() {
const coursesResponse = await fetch('https://api.nksss.live/courses');
const courses = await coursesResponse.json();
return courses.data.map((course: Course) => ({
code: course.code,
}));
}
async function fetchCourse(code: string) {
const courseResponse = await fetch(`https://api.nksss.live/courses/${code}`);
return (await courseResponse.json()).data;
}
export default async function CourseInfo({ params, searchParams }: any) {
const { code } = params;
const course: Course = await fetchCourse(code);
const courseContent = await serialize(course.content[0])
return (
<>
<main>
<ul>
<li>
<strong>Course code:</strong> {course.code}
</li>
<li>
<h2>Content</h2>
<ol>
{course.content.map((unit: string, index: number) => (
<li key={index}><MDXRemote {...courseContent}/></li>
))}
</ol>
</li>
</ul>
</main>
</>
);
}
Commenting out the Content <li> tag removes the error
Seems like the issue is in:
<li key={index}><MDXRemote {...courseContent}/></li>
interestingly this didn't happen for me when i last used next-mdx-remote, but it happens now
I see
to workaround, wrap MDXRemote in a client component
"use client";
import { MDXRemote, MDXRemoteProps } from "next-mdx-remote";
export default function RenderMarkdown(props: MDXRemoteProps) {
return <MDXRemote {...props} />;
}
then use RenderMarkdown as if it was MDXRemote
All right, fair enough. Thanks a ton!