OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

React - How to return HTML elements in JSON

  • Thread starter Thread starter user14439
  • Start date Start date
U

user14439

Guest
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?

Code:
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:

Code:
Hello
Lorem ipsum
dolor sit amet

fiddle

<p>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?</p>

<pre><code>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>;
}
});
</code></pre>

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

<pre><code>Hello
Lorem ipsum
dolor sit amet
</code></pre>

<p><a href="https://jsfiddle.net/7jabzxvy/1/" rel="noreferrer">fiddle</a></p>
 

Latest posts

Top