Skip to content

Using Custom Components in MDX - mdx-js/react #1236

Answered by ChristianMurphy
muescha asked this question in Q&A
Discussion options

You must be logged in to vote

@muescha you're asking a few different semi-related questions here:

Question 1: how to use the MDX compiler programmatically

import unified from 'unified'
import parse from 'remark-parse'
import remark2react from 'remark-react'

unified()
  .use(parse)
  .use(remark2react)
  .processSync(this.state.text).result

This doesn't support MDX syntax because you aren't using MDX
See https://mdxjs.com/advanced/api#compiler on how to use the compiler programmatically.

Question 2: how to use MDX as a React component in the Runtime

<MDX components={components}>{this.state.text}<MDX>

I'm not sure what you have set to MDX in the above example.
Runtime is the way to parse and transform directly in t…

Replies: 4 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ChristianMurphy
Comment options

You must be logged in to vote
4 replies
@ChristianMurphy
Comment options

@ChristianMurphy
Comment options

@muescha
Comment options

@AhmedBHameed

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants