convert raw html to text in react js
<td dangerouslySetInnerHTML={{__html: this.state.actions}} />
4.4
10
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
Thank you!
10
0
Are there any code examples left?
New code examples in category Javascript