javascript - 如何在combineReducers中使用根级别的初始状态?

标签 javascript ecmascript-6 redux

我需要使用单个 reducer 更新应用程序状态的多个属性。后来我用combineReducers redux 帮助器,结合了所有 reducer 。问题是,所有其他 reducer 都从状态根向下一级操作(即在属性上),除了我需要将整个状态传递给的这个 reducer 。

如何使用 combineReducers传递根状态的函数?

const App = combineReducers({
  pages: combineReducers({
    browse: combineReducers({
      numOfItems: loadMoreItems,
      filter: setFilter
    })
  }),
  <rootState>: openPage,
  favoriteItems: addItemToFavorites,
  inBasketItems: addItemToBasket
})

我应该在 <rootState> 中放置什么?

最佳答案

Redux 文档在 Structuring Reducers - Beyond combineReducers 部分介绍了这个主题。 。基本上,您需要使用的不仅仅是 combineReducers 来完成您想要的任务。我还在我最近的博客文章Practical Redux, Part 7: Form Change Handling, Data Editing, and Feature Reducers中给出了编写一些自定义 reducer 结构逻辑的示例.

关于javascript - 如何在combineReducers中使用根级别的初始状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41781281/

相关文章:

javascript - 类型错误 : Cannot read property 'map' of null when binding tags json data which might be null

javascript - 如果我向同一个网络 worker 发送多条消息,它是否将它们排队并按顺序处理它们?

javascript - 如何将 .scss 文件作为全局导入到 app.js 父文件?

javascript - 动态更新 Angular2 指令中自定义属性的值

javascript - 提取对单独文件的 ReactDOM.render() 调用

javascript - 如何使用 'this' 关键字规避 ES6 类范围问题

Javascript在字符串中插入参数

javascript - 使用数组创建状态下拉菜单

javascript - 参数周围的大括号 - 为什么?

javascript - 在导出期间将组件连接到 redux 和多个库