我试图嵌套我的 reducer ,以给出这种结构:
state: {
data: {
dataSetOne: {
items: [],
filter: {
query: "",
includeInactive: false
}
}
}
}
我的文件结构是:
--reducers
|__index.js
|__data
|__dataSetOne.js
在
index.js
中,我导入dataSetOne.js
并导出combineReducers({ dataSetOne })
。这样很好。但是,在dataSetOne.js
中,我似乎无法嵌套filter
。是)我有的:import { combineReducers } from "redux";
function items (state = [], action) {
...
}
function query (state = "", action) {
...
}
function includeInactive (state = false, action) {
...
}
export default combineReducers({
filter: combineReducers({
includeInactive,
query
}),
items
});
这项工作的一部分;我可以毫无问题地访问
state.data.dataSetOne.items
。但是,filter
是undefined
。它甚至不存在于dataSetOne
对象上。我一定会误解
combineReducers
的工作原理,但我不知道为什么这不起作用。 最佳答案
好吧,我终于明白了!我正在将redux-persist
与localforage
结合使用,以在刷新后保持我的商店。显然,这是导致问题的原因。我清除了localforage
数据库,一切正常。
但是,我仍然不能完全理解combineReducers
的工作原理,因为我可以在我的reducer中添加简单的function
,而不必清除存储。
如果有人可以解释此行为,我将其标记为答案。
关于javascript - 嵌套的CombineReducers产生不确定的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45861560/