0

I am making my own Virtual DOM. I have a function that gets the string of HTML and returns the string of JSX. Аfter that I need to convert this string of JSX to object of JSX for comparison.

let htmlStr = '<div><div>Section 1</div><div>Section 2</div><div>Section 3</div></div>';
let jsxStr = convertHTMLtoJSX(oldMarkupStr);
  • Does this answer your question? [How do I convert a string to jsx?](https://stackoverflow.com/questions/36104302/how-do-i-convert-a-string-to-jsx) – Abdulbosid Apr 14 '20 at 19:58

1 Answers1

0

So according to the answer in the linked question, you could use NOT RECOMMENDED jsx property called: dangerouslySetInnerHTML, then your function would look like this, considering your project supports jsx:

function convertHTMLtoJSX(jsxString) {
    return (<div dangerouslySetInnerHTML={{__html: jsxString}}></div>);
}
Abdulbosid
  • 354
  • 1
  • 2
  • 12