@bobderrico/react-html-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@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

Readme

Keywords

none

Package Sidebar

Install

npm i @bobderrico/react-html-parser

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

52.4 kB

Total Files

8

Last publish

Collaborators

  • bobderrico