MDX and React components
Rspress supports MDX, a content authoring format that seamlessly combines Markdown with JSX. MDX lets you use React components directly in your documentation, pairing Markdown's concise syntax with the React ecosystem. It is ideal for building interactive, component-based technical documentation.
What is MDX
MDX combines Markdown and JSX syntax, so you can write Markdown content and use React components in the same file.
We recommend using .mdx for all documentation files. This lets you write content like regular Markdown while importing and using the built-in components provided by Rspress.
MDX fragments
In MDX, every .mdx file is compiled into a React component, which means it can be imported like any component and can freely render React components. For example:
It renders as:
Testing the use of MDX fragments and React components.
This is mdx fragment.
This is a component from tsx
In .mdx files, you can use the built-in components provided by Rspress or install React component libraries to enrich your documentation.
Routing convention
In the docs directory, MDX fragments or React components must be excluded from routing with route.exclude. For convenience, files starting with "_" are excluded by default through route.excludeConvention.
You can also place components in adjacent directories outside the docs directory. For example:
It is rendered as:
button
This is text from MDX
Escape Hatch: writing document content in tsx
It renders as:
This is content in tsx, but the styles are the same as in the documentation, such as @rspress/core. However, this text with className="rp-not-doc"@rspress/core will not take effect
TSX and HTML syntax can make it difficult to extract static information, such as local search indexes.
We recommend using .mdx files for document content and .tsx files for interactive dynamic content.
React version requirements
If react, react-dom, or react-router-dom is already installed in your project, Rspress will prioritize using the version installed in your project rather than the built-in default version.