如何在SideBarReducer中更改MenuReducer的狀態?這意味着當用戶在邊欄中執行操作時在菜單中顯示警告消息。用戶將來也會在其他減速器中執行操作,這會導致MenuReducer中的警告彈出。如何更改react.js中的另一個reducer的狀態?
MenuReducer:
import actionTypes from '../action-types';
export const initialState = {
showWarning: false,
};
export default function MenuReducer(state = initialState, action) {
switch (action.type) {
case actionTypes.REQUEST_REFRESH:
if (action.payload.unsavedChanges) {
return { ...state, showWarning: true };
}
default:
return state;
}
}
SidebarReducer:
import actionTypes from '../action-types';
export default function sideBarReducer(state = initialState, action) {
switch (action.type) {
case actionTypes.REQUEST_CLOSE:
if (action.payload.unsavedChanges) {
// Change the state of MenuReducer
}
default:
return state;
}
}