Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactMarkdown without wrapping div

I'm using ReactMarkdown component (https://github.com/rexxars/react-markdown).

It works correct. Except that all output is wrapped with a div.

After research i found the solution:

like image 451
chrisheyn Avatar asked Oct 22 '25 23:10

chrisheyn


2 Answers

My Solution:

ReactMarkdown accepts a prop "renderers". You can pass an object with keys for every node type. And when you set the key "root" to React.Fragment it renders all flat. Without the wrapping div:

<ReactMarkdown source={myMdString} renderers={{ root: React.Fragment }} />
like image 50
chrisheyn Avatar answered Oct 25 '25 13:10

chrisheyn


The latest version does not support custom root. According to sources it uses div if there is a className property and React.Fragment otherwise.

So in my case I had to remove the className

like image 37
Yozi Avatar answered Oct 25 '25 13:10

Yozi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!