Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert String to HTML on React , rich text editor

I am using React-Quill to add Rich text editor to my app.

have the next string store in my DB:

const text = '<p>Hello<strong> World</strong></p><p><strong>Next Line</strong></p>';

Now I want to "Render" the text const in a REACT component, but with the "Styuling" that HTML gives to it.

Hello World

Next Line

How can I do it? or other rich text editor to achieve that?

like image 526
Miguel Angel Marroquin Jordan Avatar asked May 02 '26 17:05

Miguel Angel Marroquin Jordan


1 Answers

You can use dangerouslySetInnerHTML

Source: https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml

const text = '<p>Hello<strong> World</strong></p><p><strong>Next Line</strong></p>';

<div dangerouslySetInnerHTML={{__html:text}} />
like image 159
Akash Gupta Avatar answered May 05 '26 07:05

Akash Gupta



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!