aknuds1/html-to-react

How to render element rather than string?

Closed this issue · 2 comments

I though I could use this library instead of dangerouslySetInnerHtml, but the sample code from the readme just returns a string, which React will escape.

import HtmlToReact from "html-to-react"

var htmlInput = '<div><h1>Title</h1><p>A paragraph</p></div>';

const parser = new HtmlToReact.Parser()
var reactElement = parser.parse(htmlInput);

const Component = () => {
  return (
    <div>{reactElement}</div>
  )
}

Thanks for providing an example @rudfoss - I guess we can close.