Reputation: 1405
I store some html source code in database, it's a block of code like this:
<div class="content"><h1>Page 1</h1></div>
Now in react I get them in a variable ({this.state.content}
), but when I try to render them the source code got displayed as a string. Here's how I use it:
<div>
{this.state.content}
</div>
On page it just shows the source code directly. How do I get them render as html source code instead of a string?
Upvotes: 0
Views: 653
Reputation: 563
Actually, you are trying to set raw HTML. Try this.
<div dangerouslySetInnerHTML={{__html: this.state.content}}></div>
Duplicate of this question
Upvotes: 2