我不确定为什么我的函数给我这个错误。在返回值的函数中,我确保所有级别都有一个 return 语句。我可以对为什么会发生此错误有第二种意见吗?该服务完美地返回数据,但是,前端看不到我的操作的返回。
我尝试了具有相同标题的其他解决方案,所以希望这不是重复
的前端:
componentDidMount() {
const { item } = this.props;
this.props.getDetails(Number)
.then((res) => {
this.setState({
data: res.response.response.Results
})
});
}
映射:
function mapDispatchToProps(dispatch) {
return {
getDetails(Number) {
dispatch(getActions.getDetails(Number));
}
};
}
函数检索:
function getDetails(Number) {
return (dispatch) => {
dispatch({ type: policyConstants.ITEM_GETDETAIL_REQUEST });
return Service.getDetails(Number)
.then(
response => {
dispatch({ type: Constants.ITEM_GETDETAIL_SUCCESS });
var pDetails = response.response.Results;
return { pDetails };
},
error => {
dispatch({ type: policyConstants.POLICY_GETDETAIL_FAILURE, error});
}
);
}
}
componentDidMount
中的this.props.getDetails(Number)
被评估为undefined
,因为mapDispatchToProps
中的getDetails
不返回任何内容。
像这样改变:
function mapDispatchToProps(dispatch) {
return {
getDetails(Number) {
return dispatch(getActions.getDetails(Number));
}
};
}