Skip to content

How to compile an MDX string to render later in React (server and client)? #1452

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

You must be logged in to vote

Taking a step back.
This doesn't really seem to be an MDX question, MDX compiles JS/JSX, which is what your example does.
The question seems to be more "How do I dynamically load React components?", or even more broadly "How do I dynamically load JavaScript?".
Both of which are outside the scope of MDX, and generally would be handled with EcmaScript Dynamic Modules, or another loader like CJS, AMD, SystemJS, etc.


in data fetching code, get a string of MDX from a CMS. This MDX may or may not reference custom elements (shortcodes). It won't contain any import statements. Compile that string, applying remark and rehype plugins if given, and return a JSON blob.
in React code, render said bl…

Replies: 1 comment 4 replies

Comment options

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

@ChristianMurphy
Comment options

@lunelson
Comment options

@ChristianMurphy
Comment options

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