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 - Latest version: 6.3.4, last published: 4 years ago. Start using react-native-render-html in your project by running `npm i react-native-render-html`. There are 186 other projects in the npm registry using react-native-render-html.
      » 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 - React component that renders an HTML string as a React component tree. Latest version: 0.3.3, last published: 5 years ago. Start using react-html-renderer in your project by running `npm i react-html-renderer`. There are 12 other projects in ...
      » npm install react-html-renderer
    
Published   Oct 25, 2021
Version   0.3.3
🌐
npm
npmjs.com › package › @fobos531 › react-native-render-html
@fobos531/react-native-render-html - npm
Start using @fobos531/react-native-render-html in your project by running `npm i @fobos531/react-native-render-html`. There are no other projects in the npm registry using @fobos531/react-native-render-html.
      » 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 › search
render html - npm search
Tiny library to render HTML documents using reactive programing primitives.
🌐
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.
Find elsewhere
🌐
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
    
🌐
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%
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
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().
🌐
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
🌐
Squash
squash.io › how-to-rendering-reactjs-code-with-npm
How to Render ReactJS Code with NPM - Squash Labs
December 13, 2023 - This code imports React and ReactDOM from the installed packages and uses ReactDOM.render() to render a simple "Hello, world!" message to the DOM. 6. Create an HTML file: Create a new file named index.html in your project directory and add the following code:
🌐
Meliorence
meliorence.github.io › react-native-render-html
Discover | React Native Render HTML
You can alter the DOM, customize and define elements models, implement custom renderers and defer rendering for asynchronous DOM inspection in a breeze. This library aims at balancing adherance to the W3C and WHATWG standards with complexity and speed. Despite React Native styles and W3C CSS numerous incompatibilities, this library reconciles both standards, and brings support for properties unavailable in React Native such as list-style-type, white-space...
🌐
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
🌐
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>
🌐
React
react.dev › reference › react-dom › server › renderToString
renderToString – React
If some component suspends (for example, because it’s defined with lazy or fetches data), renderToString will not wait for its content to resolve. Instead, renderToString will find the closest <Suspense> boundary above it and render its fallback prop in the HTML.