我收到了来自 backed 的回复,看起来像这样。但是当我尝试像这样记录数据时。render() { const { reviews } = this.props; console.log('rev', reviews.reviewList.data._embedded);它给了我这样的错误。类型错误:reviews.reviewList.data 未定义reviewDataReducer.jsxconst initialstate = { isFetching: false, reviewList: [], page: null, fetched: false, error: null};export default (state = initialstate, action) => { switch (action.type) { case actionTypes.GET_PRODUCT_REVIEWS_LOAD: return { ...state, isFetching: true }; case actionTypes.GET_PRODUCT_REVIEWS_SUCCESS: return { ...state, fetched: true, reviewList: action.payload }; case actionTypes.GET_PRODUCT_REVIEWS_ERROR: return { ...state, fetched: false, isFetching: false, error: action.error }; default: return state; }};reviewActions.jsxexport const getProductReviews = pid => dispatch => { console.log('rev pid',pid) dispatch({ type: types.GET_PRODUCT_REVIEWS_LOAD }); new _rest() .get(`/buyer/product/${pid}/review`) .then(res => { console.log("Review Action Response", res); dispatch({ type: types.GET_PRODUCT_REVIEWS_SUCCESS, payload: res }); }) .catch(error => { dispatch({ type: types.GET_PRODUCT_REVIEWS_ERROR, error: error }); });};连接const mapStateToprops = state => ({ reviews: state.reviews.data});const mapStateToDispatch = { getProductReviews};export default connect( mapStateToprops, mapStateToDispatch)(ReviewContainer);
2 回答
慕的地8271018
TA贡献1796条经验 获得超4个赞
您的信息有限,但我会尽力做到最好。
1] 错误是因为您遍历对象错误,而不是因为在这种情况下数据不存在。2] 渲染() { 常量 { 评论 } = this.props;
在这里,我觉得你使用 (mapStateToProps) 将 redux 状态映射到 prop,如果这样的话,reducer 负责你如何在 redux 状态下设置数据。
白衣染霜花
TA贡献1796条经验 获得超10个赞
问题存在于 mapStateToprops 连接内部。尝试在那里调试它。
const mapStateToprops = state => {
debugger;
return ({
reviews: state.reviews.data
});
};
打开浏览器控制台并检查 state 的值;
添加回答
举报
0/150
提交
取消
