How to safely render html in react?

Posted by Jennifer | Updated on

If you want know how to safely render html in react? Sanitize the html using the sanitize-html module, and render the sanitized string using dangerouslySetInnerHTML.

You can create a simple wrapper component:


You can also use react-sanitized-html’s SanitizedHTML component, which is a react wrapper around sanitize-html:

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers