我收到了來自 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);
reviews.reviewList.data 在 reactjs 中未定義,即使有數據
慕容708150
2022-06-05 16:18:57