@mdx-js/react vs @mdx-js/mdx vs mdx-bundler
MDX Libraries for React Comparison
1 Year
@mdx-js/react@mdx-js/mdxmdx-bundlerSimilar Packages:
What's MDX Libraries for React?

MDX is a powerful format that allows you to write JSX embedded within Markdown documents, enabling a seamless integration of rich content and interactive components. The MDX ecosystem provides tools for transforming and rendering these documents in React applications, making it easier to create documentation, blogs, and other content-rich applications with a consistent look and feel. Each package serves a unique purpose within this ecosystem, catering to different aspects of MDX processing and rendering.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
@mdx-js/react9,413,26118,56114.4 kB168 months agoMIT
@mdx-js/mdx4,448,00718,561164 kB168 months agoMIT
mdx-bundler89,5461,86264.7 kB724 months agoMIT
Feature Comparison: @mdx-js/react vs @mdx-js/mdx vs mdx-bundler

Compilation

  • @mdx-js/react:

    @mdx-js/react does not handle compilation; instead, it focuses on rendering already compiled MDX content. It provides the necessary context and components to display MDX within a React application, making it easier to integrate MDX content into your UI.

  • @mdx-js/mdx:

    @mdx-js/mdx is responsible for compiling MDX files into React components. It processes the MDX syntax, converting Markdown and JSX into a format that React can render, ensuring that all components and markdown elements are correctly transformed.

  • mdx-bundler:

    mdx-bundler compiles MDX files into a single bundle, optimizing the output for performance. It allows for pre-rendering of MDX content, which can significantly improve load times and reduce the overhead during runtime.

Integration

  • @mdx-js/react:

    @mdx-js/react is specifically tailored for use within React applications, providing components that facilitate the rendering of MDX content. It integrates seamlessly with React's component model, making it easy to include MDX in your UI.

  • @mdx-js/mdx:

    This package is designed to be integrated into build processes, allowing developers to compile MDX files as part of their application’s build step. It is essential for projects that require dynamic MDX processing during development or deployment.

  • mdx-bundler:

    mdx-bundler is ideal for static site generators and frameworks that benefit from pre-rendering. It allows developers to bundle MDX content at build time, making it easy to serve optimized content without runtime overhead.

Flexibility

  • @mdx-js/react:

    @mdx-js/react provides flexibility in rendering MDX content, allowing developers to customize how components are displayed and interact with the rest of the React application. This makes it easy to adapt MDX content to fit various design requirements.

  • @mdx-js/mdx:

    @mdx-js/mdx offers flexibility in how you define and structure your MDX files, allowing for custom components and layouts to be used within the Markdown. This flexibility is crucial for creating rich, interactive documentation and content.

  • mdx-bundler:

    mdx-bundler provides flexibility in bundling strategies, allowing developers to choose how they want to optimize their MDX files for performance. It can be configured to suit different project needs, whether for static or dynamic content.

Ecosystem Compatibility

  • @mdx-js/react:

    @mdx-js/react is designed to work seamlessly with React, leveraging the component-based architecture of React applications. It ensures that MDX content integrates well with existing React components and libraries.

  • @mdx-js/mdx:

    @mdx-js/mdx is built to work within the broader MDX ecosystem, ensuring compatibility with other MDX-related tools and libraries. This makes it a foundational package for any MDX-based project.

  • mdx-bundler:

    mdx-bundler is compatible with various static site generators and frameworks, making it a versatile choice for developers looking to incorporate MDX into their projects. It supports a range of configurations to fit different environments.

Performance Optimization

  • @mdx-js/react:

    @mdx-js/react optimizes the rendering of MDX content within React applications, ensuring that components are efficiently updated and rendered, which is crucial for maintaining performance in larger applications.

  • @mdx-js/mdx:

    @mdx-js/mdx focuses on the compilation aspect, ensuring that the output is optimized for performance during the build process. It minimizes the overhead associated with rendering MDX content at runtime.

  • mdx-bundler:

    mdx-bundler excels in performance optimization by pre-bundling MDX files, reducing the amount of work required during runtime. This leads to faster load times and a smoother user experience, especially for content-heavy applications.

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

    Select @mdx-js/react if you want to render MDX content directly in your React components. This package provides the necessary components and context to easily integrate MDX into your React application, making it ideal for displaying MDX content seamlessly.

  • @mdx-js/mdx:

    Choose @mdx-js/mdx if you need a robust tool for compiling MDX files into React components. It is essential for transforming MDX syntax into a format that React can understand, making it the backbone of MDX processing.

  • mdx-bundler:

    Opt for mdx-bundler if you require a solution that bundles MDX files at build time, allowing for optimized rendering and performance. It is particularly useful for static site generation and projects that need to pre-render MDX content.

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