Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to parse string HTML using javascript?

I have response data in form of:

'<b>How can I waive the underage fee?</b><br>\n You … have marked your age correctly before searching.'

So the question is, how can I use that data in React Component?
I have to use it between two divs. Given data is string form of html syntax.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you want to display this html content in a component, you can use dangerouslySetInnerHTML this way:

<div dangerouslySetInnerHTML={{__html:data}} />

This will inject the HTML in you DOM. As mentioned in the doc, be aware of risks involved with injecting some unknown HMTL.

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading