[v2] Add support for MDX scoped components in live preview
See original GitHub issue🚀 Feature
I’m trying to use v2 live code editor with MDX files, and seems like the context of MDX is not passed to the LivePreview component. I had a quick glance at the docusaurus-theme-live-codeblock and it seems like it could do something like described in here: https://www.christopherbiscardi.com/post/using-mdx-scope-in-react-live-scope/
Is this something we could add to the theme?
Have you read the Contributing Guidelines on issues?
Yes
Motivation
Seems like using components that are also already imported into docs file in live preview is more straight forward.
Pitch
Similar as in mentioned blog post, I think we just have to add mdx components to the context of the LivePreview in the theme. That would enable usage of live preview like this:
import { Button } from '@material-ui/core'
# Button
Some description
<Button />
\```jsx live
<Button variant="solid">test</Button>
\```
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:16 (5 by maintainers)
Top Results From Across the Web
MDX and React - Docusaurus
Docusaurus has built-in support for MDX v1, which allows you to write JSX within your Markdown files and render them as React components....
Read more >How to Add Components to Your Blog Posts with MDX
In this stream we'll build on the blog created in the first stream and add the ability to use components in blog posts...
Read more >Comparison of MDX integration strategies with Next.js
I wanted to use MDX files on my Next.js site, but I discovered that there are a lot of ways to implement MDX...
Read more >Getting started - MDX
MDX relies on JSX, so it's required that your project supports JSX as well. Any JSX runtime (React, Preact, Vue, etc.) will do....
Read more >Using MDX scope in react-live scope - Chris Biscardi
Code = ({ codeString, language, ...props }) => { · + const components = useMDXScope() · if (props['react-live']) { · return ( ·...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found

You can add your own scope by overwriting the MDX’s code component. The
<CodeBlock />component Docusaurus uses to render the live editor accepts ascopeprop that will make your own modules available in the live editor.Step-by-step guide
@docusaurus/theme-live-codeblockis installed and configured in your docusaurus configurationdocusaurus swizzle @docusaurus/theme-classic MDXComponentssrc/theme/MDXComponents/index.jsand pass your scope to the CodeBlock componentThe scope will be passed through to react-live’s LiveProvider (more info) and your own components will be available in the live editor.
#3466 Can you please look at the issue? Our work has stopped because of this.