I am parsing a HTML string to React.js and render it as HTML element using "ReactHtmlParser" suggested in that previous post React.js: Raw HTML string does not gets recognized as HTML elements from Node.js. Now, I am trying add Bootstrap style attribute on it, by doing the following:
app.get('/myCart', (req, res) => {
var data;
var htmlString ="";
var total = 0;
MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
if (err) throw err;
var dbo = db.db("cart");
dbo.collection("items").find().toArray(function(err, result) {
if (err) throw err;
console.log("here")
data = result
for(let item of data){
htmlString += "<div className=\"row\"><div className=\"col\">" + item.desc + "</div>" + "<div className=\"col\">" + item.price + "</div></div>"
total += item.price
}
console.log("total is" + total)
htmlString +="<div className=\"row\"><div>" + total + "</div><div>"
console.log(htmlString)
res.send({express: htmlString})
db.close();
});
});
My render method:
render(){
console.log(this.state.cartData)
return(
<div className="col">
<div>{ReactHtmlParser(this.state.cartData)}</div>
</div>
)
}
As you can see, it is actually className
not classname
. However, when I render it to front-end, it got error saying that Invalid DOM property classname. Did you mean className
I really have no idea because I only put className as attribute. Does it have to do with ReactHtmlParser?