我有以下减速器,用户提交评级并获得用户的评分(your_ratings)......
发生LOAD_YOURRATINGS_SUCCESS
时,正在移除两个级别的initalState,your_ratings
正在变为store.rating
的值,当我希望它为store.rating.your_ratings
时。 / p>
下面我做错了什么?感谢
import * as types from '../actions/actionTypes';
const initialState = {
rating: {},
your_ratings: {}
}
export default function ratingReducer(state = initialState, action) {
switch (action.type) {
case types.CREATE_RATING_SUCCESS:
return action.rating
case types.LOAD_YOURRATINGS_SUCCESS:
return action.your_ratings
default:
return state;
}
}
答案 0 :(得分:2)
你需要更新你的状态而不是覆盖它,你可以在传播运营商的帮助下做到这一点,比如
export default function ratingReducer(state = initialState, action) {
switch (action.type) {
case types.CREATE_RATING_SUCCESS:
return {...state, rating: action.rating}
case types.LOAD_YOURRATINGS_SUCCESS:
return {...state, your_ratings: action.your_ratings}
default:
return state;
}
}