9

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

1 Answer 1

19

You can try use dangerouslySetInnerHTML like this

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

Example

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I had forgotten about this dangerouslySetInnerHTML

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.