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

raw-html-react

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

raw-html-react

Render react components from raw html

latest
Source
npmnpm
Version
1.2.3
Version published
Maintainers
2
Created
Source

Travis npm package Coveralls

Inspired by Sethorax/react-html-converter and aknuds1/html-to-react.

A React component that converts raw HTML to React components.

On the client, no additional dependencies are used beyond React. Cheerio is used for rendering static elements for server-side rendered applications.

This is useful for rending React components from a headless CMS in client side react applications.

Install

yarn add raw-html-react

or

npm install raw-html-react

Example

import React from 'react';
import ReactHtml from 'raw-html-react';
import MyComponent from '../components/MyComponent';

class Example extends React.Component {
  render() {
    const html = `<div data-react-component="MyComponent"></div>`;
    return <ReactHtml html={html} componentMap={{ MyComponent }} />;
  }
}

API

<ReactHtml>

This component takes raw html as text and renders react components.

Props

type ReactHtmlProps = {
  html: String,
  componentMap: Object,
  componentAttribute?: String,
  propsAttribute?: String,
  contextWrapper?: React.Node,
  onServerRender?: Function
};
Prop NameTypeRequiredDefault ValueDescription
htmlStringrequiredHTML to be parsed and rendered with React components inline.
componentMapObjectrequiredAn object where the key is the value to be used in data-react-component attributes and the value is the reference to the actual react component.
componentAttributeObjectoptionaldata-react-componentThe react component to be rendered in place of the html element
propsAttributeObjectoptionaldata-react-propsThe props that will be passed to the react component. (JSON string)
contextWrapperObjectoptionalnullWrapper component to be used when statically rendering for SSR. Typically a context provider.
onServerRenderFunctionoptionalnullA hook for modifying the server rendered html. A callback function that receives the cheerio root object ($)

HTML Attributes

data-react-component="string"

data-react-props="JSON"

Sets the props that will be passed to the react component. (JSON format)

Constructor takes plain JSON object where the key is the value to be used in data-react-component attributes and the value is the reference to the actual react component.

Keywords

react-component

FAQs

Package last updated on 06 Aug 2018

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