Convert HTML Strings Into Components – React HTML Parser

Description:

The React HTML Parser converts HTML strings directly into React components. Avoids the use of dangerouslySetInnerHTML and converts standard HTML elements, attributes and inline styles into their React equivalents.

Installation:

# Yarn
$ yarn add react-html-parser
# NPM
$ npm install react-html-parser --save

Usage:

import React from 'react';
import ReactHtmlParser, { processNodes, convertNodeToElement, htmlparser2 } from 'react-html-parser';
class HtmlComponent extends React.Component {
  render() {
    const html = '<div>HTML strings</div>';
    return <div>{ ReactHtmlParser(html) }</div>;
  }
}

Preview:

React HTML Parser

Add Comment