【发布时间】:2019-07-07 22:40:38
【问题描述】:
现在我使用 redux-starter-kit 制作了两个减速器(学生减速器和考试减速器)。我们如何在学生减速器中访问考试减速器的状态?还有,我们可以在student reducer中调用exam的dispatch函数来修改exam state的状态吗?
examReducer.js
const exam = createSlice({
initialState: {
mathScore: 0
},
reducer: {
setMathScore: (state, action) => {
state.mathScore = action.payload;
}
}
});
studentReducer.js
const student = createSlice({
initialState: {
pass: false
},
reducer: {
setMathScore: (state, action) => {
//try to get math score from exam reducer
state.pass = /*TODO*/ > 70 ? true : false;
}
}
});
store.js
const store = configureStore({
reducer: {
exam: exam.reducer,
student: student.reducer
}
});
【问题讨论】:
标签: javascript reactjs redux