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}} />
Answer from Akash Gupta on Stack OverflowYou 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}} />
react-quill supports HTML strings out of the box, so there's nothing to do except set the value property of the component with the string you receive from the database.
<ReactQuill value={text} ... />
» npm install convert-rich-text
How to convert rich text format to display in react
Rich text editor that supports html
Reframed - How to convert plain text to html code.
How to deal with Rich Text in React?
Videos
» npm install @contentful/rich-text-react-renderer
I am looking for library that provided text editor that can support images and html , bold , italic and etc. I am using now quill but I don’t know how can I setup it for html.
I asked this question earlier but seems i didn't frame it properly. So here is the problem. There is some storage which stores html files with some content in it. The storage is done using an API which accepts html string, created a file and stores the html string as .html file.
Now my problem on React side is, there is an input box where user types the content which I want to convert to html code. When user types it, it is just plain text. What I want is a Library that course go through the text and place p, div, h1 etc tags in appropriate places so that I can then send this as html string to the API.
Hi,
I'm working on a Gatsby blog which imports content from Prismic.io This content includes Richt Text which I transform to HTML using prismic-dom.
What is the best way to deal with this html output in React?
Right now I'm just using 'dangerouslySetInnerHTML' but this leaves me with loads of extraneous divs, and the syntax is also pretty ugly imo.
Example:
function renderIntro() {
return d.intro.map(intro => (
<div className="intro">
<div dangerouslySetInnerHTML={{ __html: intro.intro_title.html }}></div>
<div dangerouslySetInnerHTML={{ __html: intro.intro_body.html }}></div>
</div>
));
} Is there a better way of doing this?
» npm install react-richtext