skip to Main Content

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


  1. This is not a React/html issue, you likely have some CSS overriding and tags. First solution should work just fine.

    Login or Signup to reply.
  2. First solution is totally fine and its working, please check there might be some issue with the css

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search