You should convert the fetch response first with .json()
. It returns a promise, so you can use it this way:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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) { ... |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.