Next.js Discord

Discord Forum

How to Import React Component into mdx file (App Router)?

Unanswered
Botteri's Sparrow posted this in #help-forum
Open in Discord
Botteri's SparrowOP
Has anyone managed to import and use a React component within an .mdx file with Next.js?

I'm trying to do the following:

import CodeTabs from "@alias/to/component"

<CodeTabs>
'''python
some code
'''

'''lua
some code
'''
</CodeTabs>


and followed configuration from this guide: https://nextjs.org/docs/app/building-your-application/configuring/mdx

But I can't quite get it to work. It seems like in nextjs, it's possible to define custom React elements for individual HTML elements (for the mdx to html conversion), but I haven't found much information about importing React components into mdx files using the App Router.

3 Replies

European sprat
App directory is stable since 13.4
Botteri's SparrowOP
Got it to work! It's server-side react components using next-mdx-remote