I create a test html string and try to render it in React, but my solution is not working.
Try the solution1:
const textHtml = '<p>Test</p><p><strong>Test</strong></p><p><em>Test</em></p>';
return (
<div>
<div dangerouslySetInnerHTML={{ __html: textHtml }} />
</div>
);
Try the solution 2, install html package:
import parse from 'html-react-parser';
const textHtml = '<p>Test</p><p><strong>Test</strong></p><p><em>Test</em></p>';
return (
<div>
<div>{parse(textHtml)}</div>
</div>
);
em
and strong
tags are not working both of the solutions
2
Answers
This is not a React/html issue, you likely have some CSS overriding and tags. First solution should work just fine.
First solution is totally fine and its working, please check there might be some issue with the css