Redux:没有为键提供减速机
我试着做一个这样的状态形状Redux:没有为键提供减速机,redux,Redux,我试着做一个这样的状态形状 entities: { selectedPost: 0, posts: { byId: {}, allIds: [] } } 1. 我使用了组合减速器,但我“没有为关键岗位提供减速器” 2. 所以我尝试了这种方法,它是有效的,但我不明白有什么区别 export const entitiesReducer = combineReducers({ selectedPost: selectedPost, posts:
entities: {
selectedPost: 0,
posts: {
byId: {},
allIds: []
}
}
1.
我使用了组合减速器,但我“没有为关键岗位提供减速器”
2.
所以我尝试了这种方法,它是有效的,但我不明白有什么区别
export const entitiesReducer = combineReducers({
selectedPost: selectedPost,
posts: combineReducers({
byId: postsById,
allIds: allPosts
})
});
3.
我也试过这个。它也有效
export const entitiesReducer = combineReducers({
selectedPost: selectedPost,
posts: postsReducer
});
function postsReducer(state = {}, action) {
switch (action.type) {
default:
return {
byId: postsById(state.byId, action),
allIds: allPosts(state.allIds, action)
};
}
}
我在第一个案件中犯了什么错误?
谢谢您需要更换组合减速器的顺序,请先放置后减速器您可以更换组合减速器的顺序吗?首先放置postsReducer
combineReducers
associates state属性到同名的reducer函数如果试图更改没有相应名称的reducer的存储变量,则会遇到此类错误
export const entitiesReducer = combineReducers({
selectedPost: selectedPost,
posts: postsReducer
});
function postsReducer(state = {}, action) {
switch (action.type) {
default:
return {
byId: postsById(state.byId, action),
allIds: allPosts(state.allIds, action)
};
}
}