क्या this.props.match.descriptionएक स्ट्रिंग या एक वस्तु है? यदि यह एक तार है, तो इसे ठीक HTML में परिवर्तित किया जाना चाहिए। उदाहरण:
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'));
परिणाम: http://codepen.io/ilanus/pen/QKgoLA?editors=1011
लेकिन अगर description: <h1 style="color:red;">something</h1>उद्धरण के बिना ''आप प्राप्त करने जा रहे हैं:
Object {
$$typeof: [object Symbol] {},
_owner: null,
key: null,
props: Object {
children: "something",
style: "color:red;"
},
ref: null,
type: "h1"
}
यदि यह एक स्ट्रिंग है और आप किसी भी HTML मार्कअप को नहीं देखते हैं तो मुझे केवल एक समस्या दिखाई देती है गलत मार्कअप ..
अपडेट करें
यदि आप HTMLEntcoins के साथ काम कर रहे हैं। आपको उन्हें भेजने से पहले उन्हें डीकोड करने की आवश्यकता हैdangerouslySetInnerHTML इसलिए उन्होंने इसे खतरनाक कहा :)
काम करने का उदाहरण:
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'));