I have simple fetch in my react.js project:
export function getUserById(id) {
const requestOptions = {
method: 'GET',
headers: { 'Content-Type': 'application/json','Access-Control-Allow-Origin':'http://localhost:9000' },
mode: 'no-cors',
};
var res = fetch("http://localhost:9000/user/"+id);//there should be a lot of strange lambdas..
return res;
}
I use this function in other file:
var user = getUserById(userStr);
//some code
//more code
var email=user.mail;
var id = user.id;
Unfortunately - res is always Promise. I don't feel functional programming and react but I need to do it. I know that there should be some lambda expression, but I have no idea how to write them. As you see I need to take email and id from returning JSON.
Thanks in advance.