如何将CombineReducers用于嵌套Reducer

时间:2017-05-16 11:35:11

标签: reactjs redux react-redux

我尝试学习react和redux,我尝试像这样研究json:

"profile": {},
"activities": [
    {
        "id": "0",
        "components": [
            {"id":1,"name":"test1"},
            {"id":1,"name":"test1"},
            {"id":1,"name":"test1"}
        ],
        "actions": []
    }
]

我尝试使用combine reducers将componentReducer和actionsReducer添加到活动中,但最终我遇到了很多错误。如何使用嵌套combineReducers

将这样的json建模为redux

1 个答案:

答案 0 :(得分:1)

http://redux.js.org/docs/api/combineReducers.html有一个很好的解释。

基本上:

import { createStore, combineReducers } from 'redux';
import profile from './reducers/profile';
import activites from './reducers/activites';

export default createStore(combineReducers({ profile, activies });

编辑:

哎呀我误读了!

rootReducer = combineReducers({
  router, // redux-react-router reducer
    account: combineReducers({
      profile: combineReducers({
         info, // reducer function
         credentials // reducer function
      }),
      billing // reducer function
    }),
    // ... other combineReducers
  })
});

来自https://github.com/reactjs/redux/issues/738