Trouble with Fetch in React with CORS Trouble with Fetch in React with CORS reactjs reactjs

Trouble with Fetch in React with CORS


You should convert the fetch response first with .json(). It returns a promise, so you can use it this way:

fetch(url, {  crossDomain:true,  method: 'POST',  headers: {'Content-Type':'application/json'},  body: JSON.stringify({    username: user,    password: pass,  })})  .then(response => response.json())  .then(responseJson => {    console.log(responseJson);    const tokenInfo = this.state.token;    if (tokenInfo !== undefined) {...

See https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch.