New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-typescript-raw-html

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-typescript-raw-html

React component to render raw HTML without explicitly setting innerHTML property.

latest
Source
npmnpm
Version
0.0.9
Version published
Weekly downloads
36
89.47%
Maintainers
1
Weekly downloads
 
Created
Source

react-raw-html

How to?

Simply:

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { HTMLComponent } from 'react-raw-html';

const html = `
    <div align="right">Text in div</div>
    <span draggable="false">Text in span</span>
    <a href="http://google.com/">Link to Google</a>
`;
const container = document.querySelector('#container');

ReactDOM.render(<HTMLComponent rawHTML={html}/>, container);

Why?

Because sometimes it is entirely correct to use the server-side rendering to generate pure HTML without any React at all (think Python libraries like Plotly or Bokeh, for example). But the output of these libraries, when used directly in React app, forces one to jump through hoops just to render it somehow with all those inline scripts, and even more - to render it correctly and efficiently. This package is intended to incapsulate these "hoops" inside it.

How?

The approach is fairly simple:

  • insert the raw HTML string into DOM object (for example, <div>);
  • traverse the children of this object;
  • convert each child into React element.

That's all, really?!

Well, there were two main caveats:

  • we have to manually convert DOM properties to React ones;
  • and what is sometimes more important: the scripts, when inserted by React <script> component, won't run automatically.

Although, you shouldn't worry about these cases. I should.

Will it work in any possible case? Is it production-ready?

It needs to be thoroughly tested, I can't guarantee this for now. And furthermore, there is no protection from arbitrary scripts execution yet - it will be added in the stable version.

Keywords

react

FAQs

Package last updated on 13 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts