in React JS by
Q:

How to pretty print JSON with React?

1 Answer

0 votes
by

We can use <pre> tag so that the formatting of the JSON.stringify() is retained:

const data = { name: 'John', age: 42 }

class User extends React.Component {
  render() {
    return (
      <pre>
        {JSON.stringify(data, null, 2)}
      </pre>
    )
  }
}

React.render(<User />, document.getElementById('container'))
Click here to read more about React JS
Click here to read more about Insurance

Related questions

0 votes
asked Jul 2, 2019 in React JS by Venkatshastri
0 votes
asked Dec 8, 2020 in React JS by SakshiSharma
0 votes
0 votes
asked Mar 4, 2020 in React JS by JackTerrance
0 votes
asked Mar 3, 2020 in React JS by miceperry
+1 vote
0 votes
asked Mar 2, 2020 in React JS by RShastri
0 votes
...