dispathcしているのにstoreが更新されない時
< もともと書いていたReducer>
export default function postListReducer(state = [], action) {
switch (action.type) {
case ActionType.FETCH_POST_LIST:
return action.postList.reduce((accumulator, currentV) => {
accumulator.push(currentV);
return accumulator;
}, state);
default:
return state;
}
}
< 修正したReducer >
export default function postListReducer(state = [], action) {
switch (action.type) {
case ActionType.FETCH_POST_LIST:
return [...state, ...action.postList];
default:
return state;
}
}
元のコードだともともとのstateを変更してしまっています。
Reducerでは新規にオブジェクトや配列を返す必要があるので、正しく動作していませんでした。
(State自体は変更されるが、componentWillReceivePropsが動作しない。)
以上。