I\'m having trouble dealing with facebook\'s ReactJS. Whenever I do ajax and want to display an html data, ReactJS displays it as text. (See figure below)
For those still experimenting, npm install react-html-parser
When I installed it it had 123628 weekly downloads.
import ReactHtmlParser from 'react-html-parser'
<div>{ReactHtmlParser(htmlString)}</div>
There are now safer methods to accomplish this. The docs have been updated with these methods.
Other Methods
Easiest - Use Unicode, save the file as UTF-8 and set the charset
to UTF-8.
<div>{'First · Second'}</div>
Safer - Use the Unicode number for the entity inside a Javascript string.
<div>{'First \u00b7 Second'}</div>
or
<div>{'First ' + String.fromCharCode(183) + ' Second'}</div>
Or a mixed array with strings and JSX elements.
<div>{['First ', <span>·</span>, ' Second']}</div>
Last Resort - Insert raw HTML using dangerouslySetInnerHTML
.
<div dangerouslySetInnerHTML={{__html: 'First · Second'}} />
You can use the following if you want to render raw html in React
<div dangerouslySetInnerHTML={{__html: `html-raw-goes-here`}} />
Example - Render
Test is a good day