即使我的reducer函数从api获取了正确的结果,redux存储在action.data中也未定义,我的调度仍在正确的位置。
我的减速器功能:
const convertPosition = StateHelper.createAsyncOperation(MODULE, 'convertPosition');
export function $convertPosition(lat, long) {
return (dispatch) => {
dispatch(Activity.$processing(MODULE, $convertPosition.name));
dispatch(convertPosition.request());
return fetch(`${API_ENDPOINT}/shared/maps/address?latlong=${lat},${long}`, {
headers: {
Authorization: `Bearer ${AuthService.getAccessToken()}`,
},
})
.then(FetchHelper.ResponseHandler, FetchHelper.ErrorHandler)
.then((result) => dispatch(convertPosition.success(result)))
.catch((error) => dispatch(convertPosition.failure(error)))
.finally(() => dispatch(Activity.$done(MODULE, $convertPosition.name)));
};
}
我的Reducer语句:
case convertPosition.SUCCESS:
return {
...state,
locationName: action.data,
};
case convertPosition.FAILURE:
return {
...state,
locationName: null,
};
答案 0 :(得分:0)
我用邮递员检查了API之后,结果是一个数组,所以代码是:
...
.then((result) => dispatch(convertPosition.success({result: result})))
....