HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavascriptreactMajor

How to render HTML string as real HTML?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
htmlstringrenderrealhow

Problem

Here's what I tried and how it goes wrong.

This works:

Hi there!" }} />


This doesn't:



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?

Solution

Check if the text you're trying to append to the node is not escaped like this:

var prop = {
    match: {
        description: '<h1>Hi there!</h1>'
    }
};


Instead of this:

var prop = {
    match: {
        description: 'Hi there!'
    }
};


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

Code Snippets

var prop = {
    match: {
        description: '&lt;h1&gt;Hi there!&lt;/h1&gt;'
    }
};
var prop = {
    match: {
        description: '<h1>Hi there!</h1>'
    }
};

Context

Stack Overflow Q#39758136, score: 79

Revisions (0)

No revisions yet.