Overview
MDX combines Markdown with JSX, allowing you to import and use components directly in content files. The project uses MDX for blog posts and promotional content.Installation
MDX is integrated via the official Astro integration:Astro Integration
Enable MDX inastro.config.mjs:
Basic Usage
Create MDX File
Create a.mdx file in your content directory:
File Extensions
Both extensions are supported:.md- Standard Markdown.mdx- Markdown with JSX
Importing Components
Astro Components
React Components
If using React:Component Props
Content Collections with MDX
MDX files work seamlessly with Content Collections:Custom Components
Creating Reusable Components
Markdown Features
Standard Markdown
All standard Markdown works in MDX:Blockquotes
Advanced Features
JavaScript Expressions
Conditional Rendering
Mapping Data
Layout for MDX
Apply layouts to MDX content:Styling MDX Content
Global Prose Styles
Component-Specific Styles
Code Syntax Highlighting
Astro includes syntax highlighting by default:Performance
- Keep components lightweight
- Lazy load interactive components
- Use
client:loaddirective sparingly
Troubleshooting
Components Not Rendering
- Check import path is correct
- Verify component file exists
- Ensure proper export from component
Syntax Errors
- Validate frontmatter YAML
- Check JSX syntax (proper closing tags)
- Verify all props match component interface
Styling Issues
- Check Tailwind classes are not purged
- Verify global styles are imported
- Use
is:globalfor MDX content styles