MDX is a format that lets you seamlessly use JSX in your Markdown documents. You can import components, like interactive charts and embed them within your content. This makes writing long-form content with components a blast.
More details about MDX in the Official website.
Below there is an example of a graphiql
component directly imported inside the markdown
To show that component i just needed to write the following mdx
1import { MiniGraphiQL } from 'mini-graphiql'2import { Box } from '@chakra-ui/core'34export const query1 = \`5{6continents {7code8name9}10}11\`1213<Box my='40px' borderRadius='lg' overflow='hidden' shadow='xl'>14<MiniGraphiQL url='https://countries.trevorblades.com' query={query1} />15</Box>
Remember that to declare variables inside MDX you have to export them, this way mdx understands that it is jsx code instead of markdown
The example below assumes we have an exported component named Button
in a file named Button.jsx
/Button.tsx
located in the same folder as the .mdx
file we are editing.
1---2name: Hello world3---45import { Button } from './Button'67# Hello world89Hello, I'm still a mdx file, but now I have a button component !1011<Button12onClick={() => {13alert('You clicked me')14}}15>16Click me17</Button>
With MDX you can mix React Components or html-elements with regular markdown allowing you to either document your own components or create helper components that make documentation easier.