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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-dynamic-render

v2.0.1

Published

Completely replace dangerouslySetInnerHTML to render dynamic HTML and CSS in React

Readme

react-dynamic-render Completely replace dangerouslySetInnerHTML to render dynamic HTML and CSS in React

To render external HTML in React, the only way is “dangerouslySetInnerHTML” which as the name suggests can be dangerous as it makes your code vulnerable to cross-site scripting (XSS) attacks.

'stache

react-dynamic-render has zero-dependency only react as peer-dependency, making it very light. Completely eliminating the use of “dangerouslySetInnerHTML” and using React.createElement function to render HTML and CSS. With additional script to eliminate any kind of script or dangerous element/attributes.

Where to use react-dynamic-render?

If you need to use dynamic UI for a perticular component or a complete page you can use react-dynamic-render with react.

Note: Any kind of JS script will be eliminated in the process

Installation

Use the package manager npm to install react-dynamic-render.

npm install react-dynamic-render

Usage

Below is a quick example how to use react-dynamic-render:

import React from "react";
import {
  DynamicRenderJson,
  htmlReactParser,
  DynamicRender,
  vNodeToHtmlString,
} from "react-dynamic-render";

const PComponent = ({ text }) => {
  return <p>{text}</p>;
};

const html = `
<div>
  <style>
    .heading {
      color: red;
    }
  </style>
  <div>
    <h1 class="heading">Testing React Dynamic Render (react-dynamic-render)</h1>
    {"component": "CustomComponent", "props": { "text": "Hello World" }}
  </div>
</div>
`;

const index = () => {
  const htmlJson = htmlReactParser({ htmlString: html });
  console.log("htmlJson", htmlJson);
  // htmlJson {type: 'div', props: {…}}

  const htmlString = vNodeToHtmlString({
    htmlJson,
    customComponents: { // CustomComponents is not mandatory
      CustomComponent: PComponent,
    },
  });
  console.log("htmlString", htmlString);
  // htmlString <div><style> .heading { color: red; } </style><div><h1 class="heading">Testing React Dynamic Render (react-dynamic-render)</h1><p>Hello World</p></div></div>

  return (
    <div>
      <DynamicRenderJson
        htmlJson={htmlJson}
        customComponents={{ // CustomComponents is not mandatory
          CustomComponent: PComponent, 
        }}
      />
      <DynamicRender
        htmlString={htmlString}
        customComponents={{ // CustomComponents is not mandatory
          CustomComponent: PComponent, 
        }}
      />
    </div>
  );
};

export default index;

customComponents can be used to add more functionality to it

License

MIT