0 votes
in ReactJS by

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'))

Related questions

0 votes
asked Nov 5, 2023 in ReactJS by AdilsonLima
0 votes
asked Nov 3, 2023 in ReactJS by AdilsonLima
...