Skip to content
MDX logo
v1.6.21

Create React App

请注意,以下 macro 存在一个 已知的 bug, 导致目前无法进行 实时重加载。

针对 Create React App 你需要使用 mdx.macro

npx create-react-app my-app
yarn add mdx.macro

然后创建 src/App.js 文件并填入以下内容:

// src/App.js
import React, {lazy, Component, Suspense} from 'react'
import {importMDX} from 'mdx.macro'
const Content = lazy(() => importMDX('./Content.mdx'))
class App extends Component {
render() {
return (
<div>
<Suspense fallback={<div>Loading...</div>}>
<Content />
</Suspense>
</div>
)
}
}
export default App

然后创建 src/Content.mdx 文件并填充以下内容:

# Hello, world!

查看完整示例

Edit this page on GitHub
Previous:
Gatsby 集成 MDX
Next:
React Static 集成 MDX