Converting component state to JSON in React Converting component state to JSON in React reactjs reactjs

Converting component state to JSON in React


Just use JSON.stringify method in order to turn an javascript object into JSON text and store that JSON text in a string.

Also, you can use JSON.parse which turns a string of JSON text into a Javascript object.

let state = {    name : "Example",    age : "21",    description : "Some text here."}console.log(state);console.log(JSON.stringify(state));