创建1个动作但可以使用2个Reducer

时间:2018-12-17 00:55:01

标签: reactjs redux react-redux

我不知道这是正常现象,还是我的代码有误,所以我想问这个问题。

我的项目使用Redux和Redux-Saga。

This is my folder

我在我的Sell组件中创建了1个Action,以连接到Money / Reducer。效果很好,但是事情还是在我的控制台日志中,用户/还原程序也正在运行。

用户/还原器:

file 'slide_0001.jpg'
duration 0.163
file 'slide_0002.jpg'
duration 0.533
file 'slide_0003.jpg'
duration 1.067
file 'slide_0004.jpg'
duration 0.533
file 'slide_0005.jpg'
etc.

这是我的RootReducer:

const user = (state = initState, action) => {
console.log(action, "action"); //This log is running when I don't do anything with this reducer
switch() {
//switch statement here
}
}

1 个答案:

答案 0 :(得分:3)

没有错,当派发action时,该动作将流经所有reducer,因此您将需要相应的switch大小写。 Reducer不会采取任何特定的动作,这也意味着它使您可以选择从不同的Reducer更新状态。