The way we manage and deliver web content has been in constant evolution. We moved from static HTML files to complex, database-driven Content Management Systems (CMS). Today, we're on the cusp of another major evolution: treating Content as Code. This paradigm shift means applying the same principles of version control, modularity, and reusability we use for our application's source code to our content itself.
At the heart of this movement is MDX—a powerful technology that lets you write JSX, the syntax of React components, directly inside your Markdown files. It blurs the line between static documents and interactive applications.
But while MDX is revolutionary, its implementation has often been tied to complex local build environments. What if you need to render rich, component-driven content on the fly, sourced from a headless CMS or user input?
This is where mdx.do comes in, offering a simple API to dynamically compile MDX to React, making component-driven content a reality for any application.
MDX is a superset of markdown that fundamentally changes what a "document" can be. It allows you to seamlessly embed interactive React components and dynamic expressions within your content.
Imagine a standard Markdown file for a blog post:
# My Product Review
Our new product is fantastic. It has a 4.5-star rating.
Now, imagine that same post with the power of MDX:
# My Product Review
Our new product is fantastic. See what our customers think:
<StarRating rating={4.5} />
And check out its performance over time:
<InteractiveChart data={productPerformanceData} />
Suddenly, your content is no longer just static text and images. It's a living, breathing part of your application, composed of reusable, testable, and interactive components. This approach closes the gap between content creators and developers, allowing writers to leverage a pre-approved library of components to build rich, engaging experiences without ever leaving their markdown editor.
Historically, using MDX meant integrating it into a build process with tools like Webpack or Vite, typically within a framework like Next.js or Gatsby. This is perfect for static sites where content is known at build time.
However, this model breaks down for dynamic use cases:
Setting up a server-side compilation pipeline for these scenarios can be complex and brittle. You need to manage dependencies, handle security, and ensure performance.
mdx.do abstracts away all that complexity behind a simple, robust API. It allows you to dynamically compile MDX to React in real-time, without a complicated local setup.
The workflow is beautifully simple:
Let's see how easy it is to transform a string of MDX into a renderable component.
import { mdx } from "mdx.do";
const mdxContent = `
---
title: "Hello MDX!"
author: "mdx.do"
---
# Welcome to Dynamic Content
This is a JSX component rendered from a string:
<MyCustomComponent title="Welcome" />
And expressions are easy: In {new Date().getFullYear()}, MDX is powerful.
`;
// Compile the MDX string into executable code
const { code, frontmatter } = await mdx.compile(mdxContent);
// `code` can now be safely evaluated and rendered
// in your React application.
// `frontmatter` contains { title: "Hello MDX!", author: "mdx.do" }
The returned code is a JavaScript string that can be evaluated and rendered using a library like next-mdx-remote or run-jsx. You simply pass your React components in as scope, and they'll be rendered exactly where you placed them in the markdown.
The real magic of mdx.do lies in its ability to power truly component-driven workflows. Since you provide the components at render-time in your frontend, your content can be completely decoupled from your codebase.
Consider these use cases:
This approach empowers your entire team. Developers create a robust library of components, and content creators use them to build dynamic pages without needing developer intervention for every layout change.
The shift to "Content as Code" is here, and MDX is leading the charge. By removing the barrier of complex build tooling, mdx.do makes this powerful paradigm accessible to any developer building with React.
If you're looking to bridge the gap between static content and interactive applications, supercharge your headless CMS, or simply build better, more dynamic web experiences, it's time to give mdx.do a try.
Ready to transform your content workflow? Visit mdx.do to get started and dynamically compile your MDX to React today!