You need to setup your environment with Webpack. you can follow this tutorial: https://www.valentinog.com/blog/react-webpack-babel/

Or you can clone a react boilerplate project from github directly.

Answer from Wilson Liao on Stack Overflow
🌐
npm
npmjs.com › package › react-render-html
react-render-html - npm
November 10, 2017 - Latest version: 0.6.0, last published: 8 years ago. Start using react-render-html in your project by running `npm i react-render-html`. There are 84 other projects in the npm registry using react-render-html.
      » npm install react-render-html
    
Published   Nov 10, 2017
Version   0.6.0
Author   Hyunje Jun
🌐
npm
npmjs.com › package › react-native-render-html
react-native-render-html - npm
January 24, 2022 - import React from 'react'; import { useWindowDimensions } from 'react-native'; import RenderHtml from 'react-native-render-html'; const source = { html: ` <p style='text-align:center;'> Hello World!
      » npm install react-native-render-html
    
Published   Jan 24, 2022
Version   6.3.4
🌐
npm
npmjs.com › package › react-html-renderer
react-html-renderer - npm
October 25, 2021 - import React from 'react' import HTMLRenderer from 'react-html-renderer' // Components to which elements are mapped import Heading from './Heading' import Subheading from './Subheading' import Link from './Link' // HTML to render as React components ...
      » npm install react-html-renderer
    
Published   Oct 25, 2021
Version   0.3.3
🌐
npm
npmjs.com › search
render html - npm search
No more dangerouslySetInnerHTML, render HTML as React element.
🌐
npm
npmjs.com › package › @fobos531 › react-native-render-html
@fobos531/react-native-render-html - npm
import React from 'react'; import { useWindowDimensions } from 'react-native'; import RenderHtml from '@fobos531/react-native-render-html'; const source = { html: ` <p style='text-align:center;'> Hello World!
      » npm install @fobos531/react-native-render-html
    
Published   Jul 04, 2024
Version   6.4.1
🌐
GitHub
github.com › hatashiro › react-render-html
GitHub - hatashiro/react-render-html: Render HTML as React element, possibly replacing dangerouslySetInnerHTML · GitHub
May 4, 2020 - Can make use of React's reconciliation ... Can result in slower rendering speed, mainly for parsing · Install with NPM: npm i --save react-render-html ·...
Starred by 214 users
Forked by 30 users
Languages   JavaScript
🌐
npm
npmjs.com › package › @vandrei977 › react-native-render-html
@vandrei977/react-native-render-html - npm
Start using @vandrei977/react-native-render-html in your project by running `npm i @vandrei977/react-native-render-html`. There are no other projects in the npm registry using @vandrei977/react-native-render-html.
      » npm install @vandrei977/react-native-render-html
    
Published   Mar 14, 2025
Version   6.3.106
Find elsewhere
🌐
Socket
socket.dev › npm › package › react-native-render-html
react-native-render-html - npm Package Security Analysis - S...
The hackable, full-featured Open Source HTML rendering solution for React Native. ... The npm package react-native-render-html receives a total of 412,671 weekly downloads.
Top answer
1 of 14
279

There are now safer methods to render HTML. I covered this in a previous answer here. You have 4 options, the last uses dangerouslySetInnerHTML.

Methods for rendering HTML

  1. Easiest - Use Unicode, save the file as UTF-8 and set the charset to UTF-8.

    <div>{'First · Second'}</div>

  2. 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>

  3. Or a mixed array with strings and JSX elements.

    <div>{['First ', <span>&middot;</span>, ' Second']}</div>

  4. Last Resort - Insert raw HTML using dangerouslySetInnerHTML.

    <div dangerouslySetInnerHTML={{__html: 'First &middot; Second'}} />

2 of 14
102

dangerouslySetInnerHTML is React’s replacement for using innerHTML in the browser DOM. In general, setting HTML from code is risky because it’s easy to inadvertently expose your users to a cross-site scripting (XSS) attack.

It is better/safer to sanitise your raw HTML (using e.g., DOMPurify) before injecting it into the DOM via dangerouslySetInnerHTML.

DOMPurify - a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. DOMPurify works with a secure default, but offers a lot of configurability and hooks.

Example:

import React from 'react'
import createDOMPurify from 'dompurify'
import { JSDOM } from 'jsdom'

const window = (new JSDOM('')).window
const DOMPurify = createDOMPurify(window)

const rawHTML = `
<div class="dropdown">
  <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
    Dropdown
    <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
  </ul>
</div>
`

const YourComponent = () => (
  <div>
    { <div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(rawHTML) }} /> }
  </div>
)

export default YourComponent
🌐
W3Schools
w3schools.com › react › react_render.asp
React Render HTML
React renders HTML to the web page via a container, and a function called createRoot().
Top answer
1 of 14
279

There are now safer methods to render HTML. I covered this in a previous answer here. You have 4 options, the last uses dangerouslySetInnerHTML.

Methods for rendering HTML

  1. Easiest - Use Unicode, save the file as UTF-8 and set the charset to UTF-8.

    <div>{'First · Second'}</div>

  2. 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>

  3. Or a mixed array with strings and JSX elements.

    <div>{['First ', <span>&middot;</span>, ' Second']}</div>

  4. Last Resort - Insert raw HTML using dangerouslySetInnerHTML.

    <div dangerouslySetInnerHTML={{__html: 'First &middot; Second'}} />

2 of 14
102

dangerouslySetInnerHTML is React’s replacement for using innerHTML in the browser DOM. In general, setting HTML from code is risky because it’s easy to inadvertently expose your users to a cross-site scripting (XSS) attack.

It is better/safer to sanitise your raw HTML (using e.g., DOMPurify) before injecting it into the DOM via dangerouslySetInnerHTML.

DOMPurify - a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. DOMPurify works with a secure default, but offers a lot of configurability and hooks.

Example:

import React from 'react'
import createDOMPurify from 'dompurify'
import { JSDOM } from 'jsdom'

const window = (new JSDOM('')).window
const DOMPurify = createDOMPurify(window)

const rawHTML = `
<div class="dropdown">
  <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
    Dropdown
    <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
  </ul>
</div>
`

const YourComponent = () => (
  <div>
    { <div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(rawHTML) }} /> }
  </div>
)

export default YourComponent
🌐
GitHub
github.com › meliorence › react-native-render-html
GitHub - meliorence/react-native-render-html: iOS/Android pure javascript react-native component that renders your HTML into 100% native views · GitHub
npm install react-native-render-html · yarn add react-native-render-html · import React from 'react'; import { useWindowDimensions } from 'react-native'; import RenderHtml from 'react-native-render-html'; const source = { html: ` <p ...
Starred by 3.6K users
Forked by 626 users
Languages   TypeScript 76.5% | MDX 11.1% | JavaScript 8.2% | SCSS 3.4%
🌐
npm
npmjs.com › package › react-html-element
react-html-element - npm
import React, { useState, useEffect } from 'react'; import ReactDOM from 'react-dom'; import ReactHTMLElement from 'react-html-element'; class IncrementerComponent extends ReactHTMLElement { connectedCallback(): void { this.render(<Incrementer />); } } customElements.define('incrementer', ReactTestComponent);
      » npm install react-html-element
    
Published   Mar 05, 2025
Version   4.0.5
Author   Steve Matney
🌐
React
react.dev › reference › react-dom › server › renderToString
renderToString – React
Importing react-dom/server on the client unnecessarily increases your bundle size and should be avoided. If you need to render some component to HTML in the browser, use createRoot and read HTML from the DOM:
🌐
npm
npmjs.com › package › react-html-render
react-html-render - npm
June 2, 2016 - Latest version: 1.0.3, last published: 9 years ago. Start using react-html-render in your project by running `npm i react-html-render`. There are no other projects in the npm registry using react-html-render.
      » npm install react-html-render
    
Published   Jun 02, 2016
Version   1.0.3
Author   HsuTing
🌐
npm
npmjs.com › package › @builder.io › react-native-render-html
@builder.io/react-native-render-html - npm
June 26, 2024 - import React from 'react'; import { useWindowDimensions } from 'react-native'; import RenderHtml from 'react-native-render-html'; const source = { html: ` <p style='text-align:center;'> Hello World!
      » npm install @builder.io/react-native-render-html
    
Published   Jun 26, 2024
Version   6.3.4
Author   Meliorence
🌐
Npm
npm.io › package › react-render-html
React-render-html NPM | npm.io
import renderHTML from 'react-render-html'; renderHTML("<a class='github' href='https://github.com'><b>GitHub</b></a>") // => React Element // <a className="github" href="https://github.com"><b>GitHub</b></a>
🌐
Npm
npm.io › package › react-native-render-html
React-native-render-html NPM | npm.io
@jsamr/counter-style@jsamr/react-native-li@native-html/transient-render-engine@types/ramda@types/urijsprop-typesramdastringify-entitiesurijs