PACKAGE · MARKDOWN

@mdx-js/react

React context for MDX

WEEKLY DOWNLOADS 7.9M
STARS 19.6K
FORKS 1.2K
OPEN ISSUES 22
GZIP SIZE 3.4 kB
UNPACKED SIZE 14.4 kB
DEPENDENCIES 2
LAST UPDATED 9mo ago
DOWNLOAD TRENDS

@mdx-js/react downloads — last 12 months

Download trends for @mdx-js/react1 download series from Jun 2025 to May 2026. Use left and right arrow keys to inspect monthly values.016.9M33.8M50.7M67.6MJun 2025SepDecMarMay 2026
@mdx-js/react
ABOUT @MDX-JS/REACT

MDX enables you to write rich, interactive content using JSX syntax directly within Markdown files. The `@mdx-js/react` package provides the necessary React context and components to seamlessly integrate MDX content into your React applications. It bridges the gap between content authors and developers, allowing for reusable React components to be embedded directly within Markdown, enhancing the expressiveness and interactivity of static content.

This package is designed for developers who want to leverage the power of React components within their content management workflow. Its core philosophy centers around providing a smooth, low-friction experience for embedding dynamic UI elements into Markdown. By offering a dedicated React provider and a straightforward API, it empowers content creators to use familiar React patterns without needing deep backend knowledge, while developers maintain full control over their component library.

The primary mechanism through which `@mdx-js/react` operates is by providing a `MDXProvider` component. This component allows you to map Markdown elements (like headings, paragraphs, lists) to custom React components. It also exposes a `useMDXComponents` hook, enabling you to access and even dynamically update these mappings within your application's logic. This pattern facilitates consistent theming and custom styling across all your MDX-rendered content.

Integration points are extensive, primarily within the React ecosystem. It fits naturally into build processes powered by tools like Webpack or Vite when configured to process MDX files. Furthermore, frameworks built on React, such as Next.js or Gatsby, can easily incorporate this package to render content managed in MDX format. The package itself is a key dependency for many static site generators and content platforms that utilize MDX.

With a bundle size of just 3.4 kB (gzip), `@mdx-js/react` adds minimal overhead to your application's JavaScript payload. Its efficient design ensures that integrating MDX content does not significantly impact initial load times. The package is part of the mature MDX.js ecosystem, known for its stability and adherence to web standards, offering a reliable solution for content-driven React applications.

While powerful, developers should be aware that `@mdx-js/react` is primarily focused on the rendering aspect within a React environment. It does not handle the parsing or compilation of MDX files; this is typically managed by other packages within the MDX.js suite, like `@mdx-js/mdx`. Ensuring that MDX files are correctly compiled before being passed to the React provider is a crucial step in the workflow.

WHEN TO USE
  • When embedding interactive React components, such as charts or forms, directly within Markdown-based documentation.
  • When you need to map standard Markdown elements (e.g., `h1`, `p`, `a`) to custom React components for consistent theming or branding.
  • When building a content-heavy React application where content authors can leverage JSX within Markdown.
  • When integrating with static site generators or frameworks that support MDX processing, like Next.js or Gatsby.
  • When using the `MDXProvider` to inject global props or context to all MDX-rendered content.
  • When needing to access and potentially override component mappings dynamically within your React application using `useMDXComponents`.
WHEN NOT TO USE
  • If your content requirements are purely static text and simple Markdown, a dedicated Markdown renderer without React dependencies may be more appropriate.
  • If you are not using React as your primary front-end framework, as this package is React-specific.
  • If you only need basic Markdown rendering and want to avoid the additional complexity of JSX compilation and React context.
  • When the compilation of MDX files into JavaScript is handled by a separate, non-React build process and you only need a lightweight Markdown renderer.
  • If your project uses a different component model or framework where React is not present.

CORRECTIONS

Spot wrong data here?

A short note helps us fix it.

Anonymous · No account · No email back

COMPARISONS 4
@mdx-js/react vs remark ★ 8.7K · 2.2M/wk @mdx-js/react vs rehype ★ 2.2K · 2.0M/wk @mdx-js/react vs shiki ★ 13.4K · 7.8M/wk @mdx-js/react vs marked ★ 36.9K · 22.8M/wk