How to safely render html in react?

Posted by Jennifer | Updated on | Reactjs

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:

Usage:

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[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers