npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

html-styled-react-parser

v1.0.1

Published

A React component to replace html strings with react and styled components

Readme

html-styled-react-parser

Convert a string of HTML to JSX with the option to replace specified elements with specific components or styled-components while maintaining child DOM structure.

The motivation behind this package was to be able to define a set of default styled components and still have these be applied to any static markup that was imported from external data sources.

Please note

Ensure that you trust the HTML before using. This requires that you have React and styled-components installed in your project

Installation

npm i html-styled-react-parser react styled-components

Usage

import Parser from 'html-styled-react-parser'
import YourComponent from 'path/to/your/component'

const html = '<p>Your HTML...</p>'
const replacements = {
  p: YourComponent
}

const SomeComponent = () => (
  ...

  <Parser html={html} replacements={replacements} />

  ...
)

or

import { parse } from 'html-styled-react-parser'
import YourComponent from 'path/to/your/component'

const html = '<p>Your HTML...</p>'
const replacements = {
  p: YourComponent
}

const SomeComponent = () => (
  ...

  {parse(html, replacements)}

  ...
)

Props

html (string): Your HTML replacements ({}): Your replacements object, see below

Configuration

Specify the replacements you want to make using the a config object in the following format:

{
  [tag name] : (React Component or Styled Component)
}

Example:

{
  b: styled.b`color: blue;`
  imageofcat: () => <img src='link to cat image' alt='Pretty kitty cat'>
}

Any tags not included in your config object will be rendered in their standard form. For example, failure to specify an em key will result in any <em> elements being rendered as such in JSX.

Passing props to components

All attributes in your HTML tag will be passed to the relevant JSX

Example:

const html = '<b someprop="prop!"></b>'

results in

() => <Component someprop='prop'></Component>

As this is a string, these props will be passed in as strings, if you want to do anything more complicated with objects you would need to handle that inside your component as required. For example using JSON.parse()

Importing replacements in multiple locations

You can avoid having to import replacements into every location you use the component by creating a wrapper component to pass the replacements automatically and then using that instead.

import Parser from 'html-styled-react-parser'

const replacements = {}

const ParserWrapper = ({ html }) => <Parser html={html} replacements={replacements} />

export default ParserWrapper