I am trying to append html in my react app but when I place my variable like this {this.state.htmlStr} it shows whole html string along with HTML tags as output on the web page. Is there a direct way in react to render HTML or any package that can be useful.
The code I am using is as below
import React from 'react';
class AboutPage extends React.Component {
constructor() {
super();
this.state = {
htmlStr = '<p>Hello World</p>'
}
}
render() {
return (
<div>{this.state.htmlStr}</div>
)
}
}
The simplest way to do that is by using 'react-render-html' package. You can install this package by below command
After installing the package you can use this in your code to render HTML