MDX Children #1954
-
Suppose I want to use a React component inside my MDX which has children or props that involve further exposition. It seems my options are to write JSX (which is unfortunate since MDX is more convenient) or to split out every one of these into a separate file (which is impractical if these children/props are small and come by the dozens). I'm thinking of something along these lines:
(Of course, that isn't going to work as is. There would need to be some syntax like curly braces for JSX that switches back to MDX mode.) Anyway, my question is about whether there are any approaches that might be better than the two I outlined above for this kind of use case. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Could you expand what you mean by this? Some ways to do interleaving: JavaScript tagged templatesUsing https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates to treat the content of the template string as markdown or MDX content. # Exercises
What's 1 + 1?
<MultipleChoice
options={[{
answer: 2,
response: mdx`*Nice!*`
},{
answer: 3,
response: mdx`**Too** big!`
}
]}
/> Using declarative JSX components, with Markdown childrenUsing https://reactjs.org/docs/context.html to allow components to decoratively describe their content and communicate with each other. # Exercises
What's 1 + 1?
<MultipleChoice>
<Option>
<Answer>2</Answer>
<Response>*Nice!*</Response>
</Option>
<Option>
<Answer>3</Answer>
<Response>**Too** big!</Response>
</Option>
</MultipleChoice> note inside JSX component children, markdown can be interleaved. |
Beta Was this translation helpful? Give feedback.
Could you expand what you mean by this?
MDX is Markdown and JSX, either can be used in this context.
Some ways to do interleaving:
JavaScript tagged templates
Using https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates to treat the content of the template string as markdown or MDX content.
Which could look something like:
Using declarative JSX components, with Markdown children
U…