0
我刚刚介绍到了redux,并且遇到了预加载状态一段时间的问题。在redux中,使用combineReader进行预加载状态
当使用单个reducer时,我使用下面的代码,它用于正常工作。有关片段::
const head = (state = {}, action) => {
switch (action.type) {
case 'TOGGLE_VISIBLITY':
if (state.head.content !== action.id) {
return state
}
state.body.visible = !state.body.visible;
return state;
default:
return state
}
}
const heads = (state = [], action) => {
switch (action.type) {
case 'TOGGLE_VISIBLITY':
state.body = state.body.map(t =>
head(t, action)
);
}
return state;
}
export const store = createStore(heads, config);
但是这不是我刚改为combinerReducers,并开始异常触发JS错误。
在传递给createStore的preloadedState参数中发现意外的键“head”,“body”。预计会找到一个已知的减速键代替:“头”。意外的键将被忽略。
我的变化是::
const plannerApp = combineReducers({
heads
});
export const store = createStore(plannerApp, config);
如果你想查看完整的代码,请访问:here。
任何帮助是非常可观的。非常感谢您的时间和努力...