admin管理员组文章数量:1023827
I'm having troubles making Saga work with an API that works with Promises.
const result = yield call(
() => {
return this.getDays().then((_result) => {
console.log('result inside');
console.log(_result);
})}
);
console.log('result outside');
console.log(result);
When I read the value the value of _result inside the then(), it prints the correct value but I cannot seem to made it work outside of the yield call to further pass it down to the action dispatch (yield put).
Following the lead of similar questions I tried a bunch of stuff:
I've tried putting a return of _result inside the then(), as well as a Promise.resolve(_result).
I've also tried returning the entire yield call and putting a variable outside to assign it in the then() but nothing seems to work.
It's the first time I'm working with Promises and generators functions and Saga and Redux and React in general so I must definitely be missing something.
Also the console.log() inside then() is printed after the console.log() at the end.
Any ideas? Thank you.
I'm having troubles making Saga work with an API that works with Promises.
const result = yield call(
() => {
return this.getDays().then((_result) => {
console.log('result inside');
console.log(_result);
})}
);
console.log('result outside');
console.log(result);
When I read the value the value of _result inside the then(), it prints the correct value but I cannot seem to made it work outside of the yield call to further pass it down to the action dispatch (yield put).
Following the lead of similar questions I tried a bunch of stuff:
I've tried putting a return of _result inside the then(), as well as a Promise.resolve(_result).
I've also tried returning the entire yield call and putting a variable outside to assign it in the then() but nothing seems to work.
It's the first time I'm working with Promises and generators functions and Saga and Redux and React in general so I must definitely be missing something.
Also the console.log() inside then() is printed after the console.log() at the end.
Any ideas? Thank you.
Share Improve this question edited Apr 28, 2020 at 13:39 adriano_effe asked Apr 28, 2020 at 13:34 adriano_effeadriano_effe 472 silver badges11 bronze badges1 Answer
Reset to default 4call
in redux-saga expects a function that returns a Promise.
const result = yield call(
() => new Promise((resolve) => {
this.getDays().then((_result) => {
resolve(_result);
});
});
);
I'm having troubles making Saga work with an API that works with Promises.
const result = yield call(
() => {
return this.getDays().then((_result) => {
console.log('result inside');
console.log(_result);
})}
);
console.log('result outside');
console.log(result);
When I read the value the value of _result inside the then(), it prints the correct value but I cannot seem to made it work outside of the yield call to further pass it down to the action dispatch (yield put).
Following the lead of similar questions I tried a bunch of stuff:
I've tried putting a return of _result inside the then(), as well as a Promise.resolve(_result).
I've also tried returning the entire yield call and putting a variable outside to assign it in the then() but nothing seems to work.
It's the first time I'm working with Promises and generators functions and Saga and Redux and React in general so I must definitely be missing something.
Also the console.log() inside then() is printed after the console.log() at the end.
Any ideas? Thank you.
I'm having troubles making Saga work with an API that works with Promises.
const result = yield call(
() => {
return this.getDays().then((_result) => {
console.log('result inside');
console.log(_result);
})}
);
console.log('result outside');
console.log(result);
When I read the value the value of _result inside the then(), it prints the correct value but I cannot seem to made it work outside of the yield call to further pass it down to the action dispatch (yield put).
Following the lead of similar questions I tried a bunch of stuff:
I've tried putting a return of _result inside the then(), as well as a Promise.resolve(_result).
I've also tried returning the entire yield call and putting a variable outside to assign it in the then() but nothing seems to work.
It's the first time I'm working with Promises and generators functions and Saga and Redux and React in general so I must definitely be missing something.
Also the console.log() inside then() is printed after the console.log() at the end.
Any ideas? Thank you.
Share Improve this question edited Apr 28, 2020 at 13:39 adriano_effe asked Apr 28, 2020 at 13:34 adriano_effeadriano_effe 472 silver badges11 bronze badges1 Answer
Reset to default 4call
in redux-saga expects a function that returns a Promise.
const result = yield call(
() => new Promise((resolve) => {
this.getDays().then((_result) => {
resolve(_result);
});
});
);
本文标签: javascriptIn Reduxsagahow to get a result from a yield call to a PromiseStack Overflow
版权声明:本文标题:javascript - In Redux-saga, how to get a result from a yield call to a Promise? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745530915a2154746.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论