React, print object on page

I have most of the data (list) stored in the state that I want to print on my page in response.

I tried -

<div>{JSON.stringify(myObject)}</div> 

and

  <div>{myObject.toString()}</div> 

tostring does not work, but I thought I would give it a shot. I'm not sure how to do this, I know if I was in angular, I could store the object in the $ scope variable and just {{myVar}} on the page to render the object. Is there a way to do this quickly? Thanks

+5
source share
1 answer

I think your example should work. Not sure which view you are hoping for, but I will give a jsfiddle example where I use JSON.stringify to print an object.

https://jsfiddle.net/5yq9fev6/1/

 var world = { 'abc' : [1, 2, 3], 'b': { 1: 'c' } } var Hello = React.createClass({ render: function() { return ( <div> <div>{JSON.stringify(world)}</div> </div> ) } }); React.render(<Hello />, document.getElementById('container')); 
+10
source

Source: https://habr.com/ru/post/1233894/


All Articles