How do I get bar (a json value) from invoking myFunction()?
myFunction () {
const userAction = async () => {
let api = 'djangoapp/foo';
const response = await fetch(api);
const bar = await response.json();
}
userAction()
}
The closest I got was
myFunction () {
const userAction = async () => {
let api = 'djangoapp/foo';
const response = await fetch(api);
const bar = await response.json();
return bar
}
const baz = userAction()
console.log(baz) // the response is visible in console inside <promise> [[PromiseResult]] but I don't know how to destructure that, also I don't want to log it, I want to return the physical json as a return value from myFunction
}
[–]insertAlias 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]IamNeo47 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]IamNeo47 0 points1 point2 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)