Mı this.props.match.descriptionbir dize veya bir nesne? Bir dizeyse, HTML'ye dönüştürülmelidir. Misal:
class App extends React.Component {
constructor() {
super();
this.state = {
description: '<h1 style="color:red;">something</h1>'
}
}
render() {
return (
<div dangerouslySetInnerHTML={{ __html: this.state.description }} />
);
}
}
ReactDOM.render(<App />, document.getElementById('root'));
Sonuç: http://codepen.io/ilanus/pen/QKgoLA?editors=1011
Bununla birlikte, açıklama <h1 style="color:red;">something</h1>tırnaksız ise '', şunları elde edeceksiniz:
Object {
$$typeof: [object Symbol] {},
_owner: null,
key: null,
props: Object {
children: "something",
style: "color:red;"
},
ref: null,
type: "h1"
}
Bu bir dizeyse ve herhangi bir HTML biçimlendirmesi görmüyorsanız, gördüğüm tek sorun yanlış biçimlendirmedir ..
GÜNCELLEME
HTML Varlıkları ile uğraşıyorsanız, göndermeden önce bunların kodunu çözmeniz gerekir dangerouslySetInnerHTML, bu yüzden buna "tehlikeli" denir :)
Çalışma örneği:
class App extends React.Component {
constructor() {
super();
this.state = {
description: '<p><strong>Our Opportunity:</strong></p>'
}
}
htmlDecode(input){
var e = document.createElement('div');
e.innerHTML = input;
return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
}
render() {
return (
<div dangerouslySetInnerHTML={{ __html: this.htmlDecode(this.state.description) }} />
);
}
}
ReactDOM.render(<App />, document.getElementById('root'));