We can use
tag so that the formatting of the<pre>
is retained:JSON.stringify()
const data = { name: "John", age: 42 };function User {return <pre>{JSON.stringify(data, null, 2)}</pre>;}const container = createRoot(document.getElementById("container"));container.render(<User />);
See Class
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"));