如何在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;
}
}