Closed xiayulu closed 5 years ago
You seem to be asking several questions all at once, so I think it’s good to start by reading the Getting Started doc!
Question 1
A real world use case is our loader.
Before answering more questions: what is your actual problem? What do you want to do? I feel like this is an XY problem (wikipedia, stackoverflow)
👋 @xiayulu
I'm going to try and answer your questions. If we don't address everything please feel free to reach out on Spectrum.
As @wooorm stated, the best real world use case of the JSX is the loader. This is typically how MDX will be incorporated into a project. Just like how loaders work for .js files, our loader turns an .mdx file into a vanilla React/JSX string that can be used like a component elsewhere in an app.
// Can I use output1.jsx like a normal component?
Yep 😸
// I can't understand the
main
element below:
The main
element is nothing more than a wrapper since context providers can only have one child element. This isn't something that is necessary.
but is it only for create-react-app?
MDX can work in any React project. Most popular frameworks have built plugins/solutions so you can use MDX in Gatsby, Next.js, Razzle, React Static, or any other framework that gives you access to the webpack config.
The following code blocks are coped from mdxjs.com, and I add some
//comments
for them. You will look back when you are reading the questions below.import React, { lazy, Component, Suspense } from 'react'; import { importMDX } from 'mdx.macro'; const Content = lazy(() => importMDX('./Content.mdx')); class App extends Component { render() { return (
} } export default App;
import React from 'react' import { MDXProvider } from '@mdx-js/react' import { Heading, Text, Pre, Code, Table } from './components'
// Will this be ok? import MDXContent from './input1.mdx'
const components = { h1: Heading.H1, h2: Heading.H2, // … p: Text, code: Pre, inlineCode: Code } export default props =>