Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
90
rated 0 times [  96] [ 6]  / answers: 1 / hits: 13252  / 8 Years ago, thu, january 28, 2016, 12:00:00

I have a JSON file that contains HTML elements in a string - Is it possible to return the data in React/JSX as valid rendered HTML?



var Hello = React.createClass({
render: function() {
var exampleJSONData = {
item: Hello,
text: <p>Lorem ipsum</p><p>dolor sit amet</p>
}
return <div>{data.item} {data.text}</div>;
}
});


Returns : Hello <p>Lorem ipsum</p><p>dolor sit amet</p> instead of:



Hello
Lorem ipsum
dolor sit amet


fiddle


More From » json

 Answers
3

You can try use dangerouslySetInnerHTML like this



<div dangerouslySetInnerHTML={ {__html: data.text} } />


Example


[#31241] Wednesday, January 27, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
makiyac

Total Points: 470
Total Questions: 100
Total Answers: 115

Location: Botswana
Member since Sat, Jan 7, 2023
1 Year ago
;