Answers for "display raw html as plain text react js"

0

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
Posted by: Guest on April-20-2021

Code answers related to "display raw html as plain text react js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language