1.0.0 • Published 3 years ago

@bobderrico/react-html-parser v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@bobderrico/react-html-parser

A lightweight parser to convert an HTML string into React elements

NPM JavaScript Style Guide

Install

npm install --save @bobderrico/react-html-parser

Usage

import React from 'react'
import { parseHTML } from '@bobderrico/react-html-parser'

const html = '<h1><strong>Hello</strong> world!</h1>'

const Component = () => {
  return <div>{parseHTML(html)}</div>
}

The above <Component /> would render as so:

<div>
  <h1><strong>Hello</strong> world!</h1>
</div>

For more examples, see https://bobderrico80.github.io/react-html-parser/

Inspiration

There are several other solutions out there that solve a similar problem, html-react-parser, react-html-parser, and html-to-react to name a few. I wanted to challenge myself to build one of my own with a more familiar API, especially in regards to the replacer function, as that function is called with an HTMLElement.

This package relies on DOMParser and therefore currently only works in the browser.

License

MIT © bobderrico80