我正在尝试在购物车操作中调度并调用函数getUnaddedCartItems:
cartRedirect = () => {
this.props.dispatch(getUnaddedCartItems().then((result) => {
if (result.length === 0) {
this.setState({unaddedCartItems: result});
}
}).catch(err => {
Actions.cart();
}));
}
我能够开始行动,断点到达第一行,但是由于某种原因,它不会继续前进到下一行,而是立即跳出!
然后我得到了错误。我不明白为什么它不尝试进入我的异步呼叫。谁能告诉我为什么会这样以及如何纠正错误?
您应该分派重击操作,然后处理返回的诺言。
this.props.dispatch(createMyThunkActionReturningPromise())
.then(handleMyPromise)
.catch(handleMyPromseError);
问题是您在调度诺言,而不是函数(thunk动作)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句