Here’s what I tried and how it goes wrong.
This works:
JavaScript
x
2
1
<div dangerouslySetInnerHTML={{ __html: "<h1>Hi there!</h1>" }} />
2
This doesn’t:
JavaScript
1
2
1
<div dangerouslySetInnerHTML={{ __html: this.props.match.description }} />
2
The description property is just a normal string of HTML content. However it’s rendered as a string, not as HTML for some reason.
Any suggestions?
Advertisement
Answer
Check if the text you’re trying to append to the node is not escaped like this:
JavaScript
1
6
1
var prop = {
2
match: {
3
description: '<h1>Hi there!</h1>'
4
}
5
};
6
Instead of this:
JavaScript
1
6
1
var prop = {
2
match: {
3
description: '<h1>Hi there!</h1>'
4
}
5
};
6
if is escaped you should convert it from your server-side.
The node is text because is escaped
The node is a dom node because isn’t escaped