Reputation: 1047
I have nested asyc await function call as shown below.i am not able to pass the return from the first promise to the next one. What is the issue with the below code?
const ret = ProductRepository.getProductsBySameBrand(brand);
ret.then(function (result) {
shuffle(result.items).then(function (result) {
console.log(result) //console is printing proper output
return result; // This is not returning anything to the next chain
});
}).then(function (result) {
// result is undefined
context.setState({ products: result });
});
Upvotes: 2
Views: 31
Reputation: 895
Maybe I'm missing something, but can't you move the constext.setState
up to the previous promise?
const ret = ProductRepository.getProductsBySameBrand(brand);
ret.then(function (result) {
shuffle(result.items).then(function (result) {
console.log(result) //console is printing proper output
context.setState({ products: result }); // <-- move here
});
}); // <-- delete extra .then()
Upvotes: 1