Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
133
rated 0 times [  134] [ 1]  / answers: 1 / hits: 63661  / 9 Years ago, fri, april 17, 2015, 12:00:00
var Klass = React.createClass({
this.props.html_string = '<button>BUTTON_TEXT</button>';
render: function(){
return (
<div className=wrapper>
{this.props.html_string}
</div>
);
}
});


Currently {this.props.html_string} gives me a text node. How can I make this a HTML DOM node?


More From » reactjs

 Answers
10

What you want is dangerouslySetInnerHTML



https://facebook.github.io/react/tips/dangerously-set-inner-html.html



function createMarkup() { return {__html: 'First &middot; Second'}; };
<div dangerouslySetInnerHTML={createMarkup()} />


Edit: you'll want to htmlencode the string.


[#67029] Wednesday, April 15, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
donovantyriqn

Total Points: 271
Total Questions: 98
Total Answers: 113

Location: Saint Vincent and the Grenadines
Member since Sat, Sep 11, 2021
3 Years ago
;