MDX와 리액트
Docusaurus has built-in support for MDX, which allows you to write JSX within your Markdown files and render them as React components.
Check out the MDX docs to see what fancy stuff you can do with MDX.
MDX 형식은 매우 엄격하여 컴파일 오류가 발생할 수 있습니다.
Use the MDX playground to debug them and make sure your syntax is valid.
Prettier, the most popular formatter, supports only the legacy MDX v1. If you get an unintentional formatting result, you may want to add {/* prettier-ignore */}
before the problematic area, or add *.mdx
to your .prettierignore
, until Prettier has proper support for MDX v3. One of the main authors of MDX recommends remark-cli
with remark-mdx
.
Exporting components
To define any custom component within an MDX file, you have to export it: only paragraphs that start with export
will be parsed as components instead of prose.
export const Highlight = ({children, color}) => (
<span
style={{
backgroundColor: color,
borderRadius: '2px',
color: '#fff',
padding: '0.2rem',
}}>
{children}
</span>
);
<Highlight color="#25c2a0">Docusaurus green</Highlight> and <Highlight color="#1877F2">Facebook blue</Highlight> are my favorite colors.
I can write **Markdown** alongside my _JSX_!
Notice how it renders both the markup from your React component and the Markdown syntax:
I can write Markdown alongside my JSX!
Since all doc files are parsed using MDX, anything that looks like HTML is actually JSX. Therefore, if you need to inline-style a component, follow JSX flavor and provide style objects.
/* Instead of this: */
<span style="background-color: red">Foo</span>
/* Use this: */
<span style={{backgroundColor: 'red'}}>Foo</span>