@mdx-js/react vs @mdx-js/mdx vs @mdx-js/loader
MDX Libraries for React Comparison
1 Year
@mdx-js/react@mdx-js/mdx@mdx-js/loader
What's MDX Libraries for React?

MDX is a powerful format that allows you to write JSX embedded within Markdown documents. It combines the ease of writing Markdown with the flexibility of React components, enabling developers to create rich, interactive documentation and content. The MDX ecosystem consists of several packages that serve different purposes, making it easier to integrate MDX into various projects. These packages streamline the process of rendering MDX content, providing loaders for bundlers, core functionality for parsing MDX, and React components for rendering MDX content seamlessly within React applications.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
@mdx-js/react7,030,44918,13114.4 kB95 months agoMIT
@mdx-js/mdx2,782,85118,131164 kB95 months agoMIT
@mdx-js/loader574,68118,13115.1 kB95 months agoMIT
Feature Comparison: @mdx-js/react vs @mdx-js/mdx vs @mdx-js/loader

Integration with Build Tools

  • @mdx-js/react:

    This package is focused on rendering MDX content in React applications. It does not deal with the build process but provides the necessary components to display MDX content once it has been compiled.

  • @mdx-js/mdx:

    While this package does not directly integrate with build tools, it provides the core parsing capabilities needed to convert MDX into React components. It can be used in custom build setups where you want to handle MDX processing manually.

  • @mdx-js/loader:

    This package acts as a Webpack loader, allowing you to import MDX files directly into your JavaScript files as React components. It simplifies the integration process, enabling developers to leverage MDX seamlessly within their existing build systems.

Rendering Capabilities

  • @mdx-js/react:

    This package provides the components necessary to render MDX content in a React application. It includes features like MDXProvider, which allows you to customize how components are rendered within MDX.

  • @mdx-js/mdx:

    This package is responsible for the core parsing of MDX, converting it into a format that can be rendered by React. It allows for customization of how MDX content is processed before rendering.

  • @mdx-js/loader:

    The loader facilitates the transformation of MDX files into React components during the build process, ensuring that all components and Markdown content are rendered correctly when the application runs.

Customization

  • @mdx-js/react:

    Offers customization through the MDXProvider component, which allows developers to define how specific Markdown elements are rendered, enabling a tailored presentation of MDX content.

  • @mdx-js/mdx:

    This package allows for a high degree of customization in how MDX content is parsed and transformed. Developers can extend or modify the behavior of the MDX compilation process to suit their needs.

  • @mdx-js/loader:

    Customization options are limited to how MDX files are processed in the build pipeline. It primarily focuses on transforming MDX into React components without extensive customization features.

Learning Curve

  • @mdx-js/react:

    This package is easy to use for developers already familiar with React. The API is intuitive, and integrating MDX content into a React application is straightforward.

  • @mdx-js/mdx:

    This package may require a bit more understanding of how MDX works and how to integrate it into custom setups, but it is manageable for developers with a solid grasp of React and JavaScript.

  • @mdx-js/loader:

    The learning curve is relatively low for developers familiar with Webpack or similar build tools. Understanding how to configure the loader is straightforward, especially for those with experience in JavaScript bundling.

Community and Support

  • @mdx-js/react:

    The community around this package is robust, with many resources available for troubleshooting and best practices. It is widely used in the React ecosystem, making it a reliable choice for rendering MDX.

  • @mdx-js/mdx:

    This package has a strong community backing, with extensive documentation and examples available. It is actively maintained, ensuring that developers have access to the latest features and fixes.

  • @mdx-js/loader:

    As part of the MDX ecosystem, this package benefits from a growing community of users and contributors. Documentation and support resources are available to help with integration issues.

How to Choose: @mdx-js/react vs @mdx-js/mdx vs @mdx-js/loader
  • @mdx-js/react:

    Select this package if you want to render MDX content directly in your React application. It provides the necessary components and context to work with MDX files, making it ideal for projects focused on displaying MDX content with React.

  • @mdx-js/mdx:

    Opt for this package if you need the core functionality for parsing MDX files. It provides the necessary tools to compile MDX into React components, making it suitable for projects that require custom handling of MDX content without a specific bundler integration.

  • @mdx-js/loader:

    Choose this package if you are using a bundler like Webpack or Rollup and need to integrate MDX files into your build process. It allows you to import MDX files as React components, making it essential for projects that require MDX support in their asset pipeline.

README for @mdx-js/react

@mdx-js/react

Build Coverage Downloads Size Sponsors Backers Chat

React context for MDX.

Contents

What is this?

This package is a context based components provider for combining React with MDX.

When should I use this?

This package is not needed for MDX to work with React. See ¶ MDX provider in § Using MDX for when and how to use an MDX provider.

If you use Next.js, do not use this. Add an mdx-components.tsx (in src/ or /) file instead. See Configuring MDX on nextjs.org for more info.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install @mdx-js/react

In Deno with esm.sh:

import {MDXProvider} from 'https://esm.sh/@mdx-js/react@3'

In browsers with esm.sh:

<script type="module">
  import {MDXProvider} from 'https://esm.sh/@mdx-js/react@3?bundle'
</script>

Use

/**
 * @import {MDXComponents} from 'mdx/types.js'
 */

import {MDXProvider} from '@mdx-js/react'
import Post from './post.mdx'
// ^-- Assumes an integration is used to compile MDX to JS, such as
// `@mdx-js/esbuild`, `@mdx-js/loader`, `@mdx-js/node-loader`, or
// `@mdx-js/rollup`, and that it is configured with
// `options.providerImportSource: '@mdx-js/react'`.

/** @type {MDXComponents} */
const components = {
  em(properties) {
    return <i {...properties} />
  }
}

console.log(
  <MDXProvider components={components}>
    <Post />
  </MDXProvider>
)

👉 Note: you don’t have to use MDXProvider and can pass components directly:

-<MDXProvider components={components}>
-  <Post />
-</MDXProvider>
+<Post components={components} />

See ¶ React in § Getting started for how to get started with MDX and React. See ¶ MDX provider in § Using MDX for how to use an MDX provider.

API

This package exports the identifiers MDXProvider and useMDXComponents. There is no default export.

MDXProvider(properties?)

Provider for MDX context.

Parameters
  • properties (Props) — configuration
Returns

Element (JSX.Element).

useMDXComponents(components?)

Get current components from the MDX Context.

Parameters
Returns

Current components (MDXComponents from mdx/types.js).

MergeComponents

Custom merge function (TypeScript type).

Parameters
Returns

Additional components (MDXComponents from mdx/types.js).

Props

Configuration for MDXProvider (TypeScript type).

Fields

Types

This package is fully typed with TypeScript. It exports the additional types MergeComponents and Props.

For types to work, make sure the TypeScript JSX namespace is typed. This is done by installing and using the types of your framework, as in @types/react.

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, @mdx-js/react@^3, compatible with Node.js 16.

Security

See § Security on our website for information.

Contribute

See § Contribute on our website 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.

License

MIT © Compositor and Vercel