MDX Notes
30+ MDX interview questions — from basic syntax to compiler internals — with answers and code examples you can actually use to prep.
Here are the MDX questions you're most likely to face in interviews. They're organized by difficulty — basics first, then intermediate, then the hard stuff that senior roles ask about.
Basic Questions (1–10)
Q1: What is MDX?
Answer: MDX lets you write JSX (React components) directly inside Markdown files. It compiles down to React components, so you get interactive content while keeping Markdown's simplicity for prose.
import { Chart } from './Chart';
# Sales Report
Here's the quarterly data:
<Chart data={salesData} type="bar" />Q3: What file extension does MDX use?
Answer: .mdx. Some frameworks let you configure .md files to be processed as MDX, but .mdx is the standard.
Q4: How do you write comments in MDX?
Answer: JSX comment syntax. HTML comments will break things:
Q5: What is frontmatter in MDX?
Answer: YAML metadata at the top of the file, between --- delimiters. Stores things like title, date, tags — anything you want to access programmatically.
Q6: How do you import a component in MDX?
Answer: Standard ES module imports, placed after frontmatter but before content:
---
title: "My Page"
---
import { Button } from '../components/Button';
import Alert from '../components/Alert';
# My Page
<Button variant="primary">Click me</Button>
<Alert type="info">This is informational.</Alert>Q7: Can you use JavaScript expressions in MDX?
Answer: Yes, with curly braces. But only expressions — not statements:
Q8: Why must all HTML/JSX tags be closed in MDX?
Answer: MDX uses JSX parsing, which requires explicit closing. No self-closing shortcuts like in HTML:
{/* ✅ Correct */}
<br />
<img src="photo.png" alt="Photo" />
<hr />
{/* ❌ Invalid in MDX */}
<br>
<img src="photo.png">
<hr>Q9: What's the difference between class and className in MDX?
Answer: MDX uses JSX rules. class is a reserved word in JavaScript, so you need className:
{/* ✅ JSX attribute name */}
<div className="container">Content</div>
{/* ❌ HTML attribute name - causes error */}
<div class="container">Content</div>Q10: How do you render Markdown inside a JSX component?
Answer: Add blank lines between the JSX tags and your Markdown. Without them, the parser treats the content as plain text:
<Card>
## This is a Markdown heading
And this is a **Markdown** paragraph with *formatting*.
- List item one
- List item two
</Card>Without the blank lines, the content may be treated as plain text.
Intermediate Questions (11–20)
Q11: What are remark and rehype plugins?
Answer: Remark plugins transform the Markdown AST (mdast). Rehype plugins transform the HTML AST (hast). Together they form the MDX processing pipeline:
Q12: How does component mapping (MDXProvider) work?
Answer: MDXProvider lets you swap out default HTML elements for custom React components globally. No need to import them in every MDX file:
Q13: What is the difference between MDX v1 and MDX v3?
Answer:
| Feature | MDX v1 | MDX v3 |
|---|---|---|
| JSX runtime | Classic (React.createElement) | Automatic (_jsx) |
| Provider | MDXProvider wrapper required | Optional, uses context |
| Compilation | Babel-based | ESM-based, faster |
| Output format | CommonJS | ES modules |
| Expression support | Limited | Full JavaScript expressions |
| Error messages | Cryptic | Clear with line numbers |
| Performance | Slower compilation | Significantly faster |
Q14: How do you pass data/props to an MDX document?
Answer: MDX files are React components. Pass props like you would to any component:
// Rendering an MDX file as a component
import MyDocument from './content/page.mdx';
function Page() {
return <MyDocument author="Jane" version="2.0" />;
}# Documentation v{props.version}
Written by {props.author}.Q15: How do you handle dynamic content in MDX?
Answer: Export variables, use expressions, or bring in client components for truly live data:
Q16: How does MDX handle layouts?
Answer: Layouts wrap your MDX content. How you set them up depends on your framework:
---
layout: "../layouts/DocsLayout.astro"
---
{/* Or via export (Next.js style) */}
export { default as Layout } from '../layouts/DocsLayout';
{/* Or via default export */}
export default function Layout({ children }) {
return <article className="prose">{children}</article>;
}
# Page Content
This will be wrapped in the layout.Q17: What is GFM and how do you enable it in MDX?
Answer: GFM (GitHub Flavored Markdown) adds tables, strikethrough, task lists, and autolinks. You need the remark-gfm plugin:
npm install remark-gfmQ18: How do you handle images in MDX?
Answer: You've got several options depending on how much control you need:
Q19: How do you conditionally render content in MDX?
Answer: JSX conditional expressions — same as you'd do in React:
export const isPro = true;
export const userRole = 'admin';
{/* Conditional with && */}
{isPro && <ProFeature />}
{/* Ternary operator */}
{userRole === 'admin' ? (
<AdminPanel />
) : (
<p>Access denied. Admin only.</p>
)}
{/* Conditional blocks */}
{process.env.NODE_ENV === 'development' && (
<div className="debug-info">
Debug mode active
</div>
)}Q20: What is the components prop in MDX?
Answer: It lets you override element renderers for a specific MDX instance (versus the global MDXProvider approach):
Advanced Questions (21–32)
Q21: Explain the MDX compilation pipeline.
Answer: MDX goes through these stages to turn your .mdx file into a React component:
| 1. Parse | Source text → MDX AST (MDXAST) |
| 2. Remark | MDXAST → Transform with remark plugins |
| 3. MDX | HAST → MDXAST → MDXHAST (HTML AST with JSX) |
| 4. Rehype | MDXHAST → Transform with rehype plugins |
| 5. Generate | MDXHAST → JavaScript/JSX output code |
| 6. Bundle/Eval | JS code → Executable React component |
import { compile } from '@mdx-js/mdx';
const code = await compile('# Hello {name}', {
remarkPlugins: [],
rehypePlugins: [],
outputFormat: 'function-body', // or 'program'
development: false,
});Q22: How do you write a custom remark plugin for MDX?
Answer: A remark plugin is a function returning a transformer that operates on the Markdown AST:
import { visit } from 'unist-util-visit';
import { toString } from 'mdast-util-to-string';
export function remarkReadingTime() {
return function (tree, file) {
// Extract all text content
const text = toString(tree);
const words = text.split(/\s+/).length;
const readingTime = Math.ceil(words / 200);
// Attach to file data (accessible in frontmatter/exports)
file.data.astro = {
...file.data.astro,
frontmatter: {
...file.data.astro?.frontmatter,
readingTime: `${readingTime} min read`,
},
};
};
}Q23: How do you write a custom rehype plugin?
Answer: Rehype plugins transform the HTML AST (hast) after the Markdown-to-HTML conversion happens:
Q24: What is the difference between compile, evaluate, and run in @mdx-js/mdx?
Answer: Three different levels of "turn MDX into something usable":
import { compile, evaluate, run } from '@mdx-js/mdx';
import * as runtime from 'react/jsx-runtime';
// compile() — Returns JavaScript code as a string
const code = await compile('# Hello', { outputFormat: 'function-body' });
// Returns: 'function _createMdxContent(props) { ... }'
// run() — Executes pre-compiled code into a component
const { default: Component } = await run(code, runtime);
// evaluate() — Compiles AND runs in one step
const { default: Component2 } = await evaluate('# Hello', {
...runtime,
remarkPlugins: [],
});
// Use case: compile() for build-time, evaluate() for runtime/dynamicQ25: How does MDX handle performance at scale?
Answer: Here are the key strategies:
Q26: How do you implement MDX remote loading?
Answer: This is for when your MDX content lives in a CMS or database instead of local files:
Q27: How do you handle MDX in a monorepo?
Answer: Share components, config, and themes across multiple MDX sites:
{
"name": "@org/mdx-config",
"exports": {
"./plugins": "./plugins/index.js",
"./config": "./mdx.config.js"
}
}Q28: What are MDX's security considerations?
Answer: MDX executes JavaScript. That's powerful but dangerous with untrusted input:
Q29: How do you implement content versioning with MDX?
Answer: Keep versioned content in separate directories:
Q30: How do you test MDX content?
Answer: Test at three levels — compilation, rendering, and link integrity:
Q31: Explain MDX's AST structure.
Answer: MDX extends the standard Markdown AST (mdast) with JSX-specific node types:
Q32: How do you create a custom MDX loader/integration?
Answer: You wire the MDX compiler into your build tool. Here's a Webpack loader example:
Bonus Questions
Q33: What frameworks support MDX natively?
Answer: Next.js (via @next/mdx), Gatsby (via gatsby-plugin-mdx), Astro (via @astrojs/mdx), Docusaurus, Remix, and any framework with Vite/Rollup/Webpack via their respective MDX plugins.
Q34: Can MDX be used with TypeScript?
Answer: Yes. Type your components, use .tsx for component files, and add type declarations for .mdx imports:
declare module '*.mdx' {
import type { ComponentType } from 'react';
const Component: ComponentType<Record<string, unknown>>;
export default Component;
export const frontmatter: Record<string, unknown>;
}Q35: What is the future of MDX?
Answer: MDX keeps getting better error messages, faster compilation, stronger TypeScript support, and deeper React Server Components integration. The ecosystem around it — doc frameworks, CMS integrations, tooling — is growing fast.
Summary
These questions cover MDX from syntax basics to compiler internals. When prepping for an interview, focus on understanding *why* things work the way they do — not just memorizing answers. Be ready to write code and explain the pipeline from source to rendered output.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for MDX Interview Questions and Answers.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this MDX Tutorial topic.
Search Terms
mdx-tutorial, mdx tutorial, mdx, tutorial, resources, interview, questions, mdx interview questions and answers
Related MDX Tutorial Topics