Project: mdx-js/mdx

Package: @mdx-js/runtime@1.6.22

  1. Dependencies: 0·Dependents: 22
  2. Parse and render MDX in a runtime environment
  1. remark 202
  2. markdown 142
  3. mdx 29
  4. react 17
  5. jsx 17
  6. mdxast 6


Build Downloads Sponsors Backers Chat

A React component that evaluates MDX.

⚠️ warning: this is not the preferred way to use MDX since it introduces a substantial amount of overhead and dramatically increases bundle sizes. It must not be used with user input that isn’t sandboxed.



npm install @mdx-js/runtime


yarn add @mdx-js/runtime


Say we have the following scripts, example.jsx:


The MDX Runtime component accepts two props:

componentsGlobally available components for the runtime
scopeVariables that are accessible in the JSX portion of the document
remarkPluginsArray of remark plugins

Example code

import React from 'react'
import {renderToString} from 'react-dom/server'
import MDX from '@mdx-js/runtime'

// Custom components:
const components = {
  h1: props => <h1 style={{color: 'tomato'}} {...props} />,
  Demo: () => <p>This is a demo component</p>

// Data available in MDX:
const scope = {
  somethingInScope: 1

// The MDX:
const children = `
# Hello, world!

{1 + somethingInScope}

<Demo />

<div>Here is the scope variable: {some}</div>

const result = renderToString(
  <MDX components={components} scope={scope} children={children} />


Now, building, bundling, and finally running it, yields:

<h1 style="color:tomato">Hello, world!</h1>
<p>This is a demo component</p>


See Contributing on mdxjs.com for ways to get started. See Support for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.


MIT © Compositor and Vercel