display raw html as plain text react js code example

Example 1: display raw html as plain text react js

I have tried this pure component:

const RawHTML = ({children, className = ""}) => 
<div className={className}
  dangerouslySetInnerHTML={{ __html: children.replace(/\n/g, '<br />')}} />
Features

Takes classNameprop (easier to style it)
Replaces \n to <br /> (you often want to do that)
Place content as children when using the component like:
<RawHTML>{myHTML}</RawHTML>
I have placed the component in a Gist at Github: RawHTML: ReactJS pure component to render HTML

Share

Example 2: convert raw html to text in react js

<td dangerouslySetInnerHTML={{__html: this.state.actions}} />

Tags:

Html Example