Is it possible to take a string and convert it into MDX? #2478
-
I'm using Next.js with MongoDB right now, and I want to make a blog page where I can put a markdown text into the body of the database, and have the markdown text be returned as a result of a GET request. Is there a way to convert the string into an MDX text and render it? I saw an earlier thread that uses a bundler to do this, but I'm not sure if it applies here |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Welcome @LinguiniThePasta! 👋
MDX a language, a text based programming/document language, it is a string.
What is the "this" that you are trying to do? |
Beta Was this translation helpful? Give feedback.
-
Once you've fetched the MDX string from your database, you can pass it to the import { MDXRemote } from 'next-mdx-remote/rsc'
export default async function Page() {
// ...fetch MDX from MongoDB
return <MDXRemote source={mdxString} />
} If you have custom components you'd like to use, you can pass them to the same I recommend looking into this section of the NextJS MDX documentation if you're still confused. |
Beta Was this translation helpful? Give feedback.
Once you've fetched the MDX string from your database, you can pass it to the
MDXRemote
component like this:If you have custom components you'd like to use, you can pass them to the same
MDXRemote
component via thecomponents
propI recommend looking into this section of the NextJS MDX documentation if you're still confused.