Skip to content

Telios-org/react-html-parser

 
 

Repository files navigation

React HTML Parser

A utility for converting HTML strings into React components. Avoids the use of dangerouslySetInnerHTML and converts standard HTML elements, attributes and inline styles into their React equivalents.

Try the Live Demo

Travis branch Coveralls npm David

Install

npm install react-html-parser

Usage

import React from 'react';
import ReactHtmlParser from 'react-html-parser';

class HtmlComponent extends React.Component {
  render() {
    const html = '<div>Example HTML string</div>';
    const options = {
      decodeEntities: true
    };
    return <div>{ ReactHtmlParser(html, options) }</div>;
  }
}

API

ReactHtmlParser(html, [options])

Takes an HTML string and returns equivalent React elements

Arguments

  • html: The HTML string to parse
  • options: Options object
    • decodeEntities=true (boolean): Whether to decode html entities (defaults to true)

About

Converts HTML strings directly into React components and provide a simple way to modify and replace the content.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%