【问题标题】:How to put reducer inside reducer如何将减速机放入减速机
【发布时间】:2019-10-07 05:36:21
【问题描述】:

我不知道,如何组合我的减速器的正确方法是什么。

在根减速器中,我有这样的页面减速器:

export default combineReducers({ 
    guidePage,
    homePage, 
})

所以,问题是,我想在 homePage reducer 中放另一个 reducer,我该怎么做呢?

像这样:

homePage : {
     propHomePage: foo,
     anotherReducer: {
         anotherReducerProp: foo2
     }
}

当我使用 combineReducers({homePage, anotherReducer}) 我得到这样的状态:

{
   homePage: {propHomePage: foo}
   anotherReducer: {anotherReducerProp: foo2}
}

这是错误的

【问题讨论】:

    标签: redux react-redux reducers


    【解决方案1】:

    基本上,将reducer 组合为一个键值对象存储。

    这应该可行:

    export default combineReducers({
      guidePage,
      homePage: combineReducers({
        propHomePage,
        anotherReducer
      })
    });
    

    【讨论】:

      【解决方案2】:

      我认为是这样的:

      const combinedHome = combineReducers({ 
          home1,
          home2, 
      })
      
      export default combineReducers({ 
          combinedHome,
          otherReducer, 
      })
      

      【讨论】:

        猜你喜欢
        • 2018-02-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多