In a simple React App that fetch response from a API, the following code with curly braces has resulting data value as undefined.
fetch('http://localhost:8000/track/?id='+this.state.input)
.then(res => {res.json()}) //Note Curly braces around {res.json()}
.then((data) => {
console.log(data);
Whereas when curly braces was removed, surprisingly it fetched and printed the response data in the console.
fetch('http://localhost:8000/track/?id='+this.state.input)
.then(res => res.json()) //No Curly braces - then works fine
.then((data) => {
console.log(data);
What is the reason for this behavior with curly braces around a Promise function? Is it not possible to use curly braces ?Why? Promises are slightly confusing though.