Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Redux:没有为键提供减速机_Redux - Fatal编程技术网

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)
      };
  }
}