要更深入地了解它,您需要了解combineReducers
例子
rootReducer = combineReducers({potato: potatoReducer, tomato: tomatoReducer})
// This would produce the following state object
{
potato: {
// ... potatoes, and other state managed by the potatoReducer ...
},
tomato: {
// ... tomatoes, and other state managed by the tomatoReducer, maybe some nice
// sauce? ...
}
}
您可以通过对传递的对象中的 reducer 使用不同的键来控制状态键名称。例如,您可以要求combineReducers({ todos: myTodosReducer, counter: myCounterReducer })
状态形状为{ todos, counter }
。
一个流行的约定是在他们管理的状态切片之后命名 reducer,因此您可以使用 ES6 属性简写表示法:combineReducers({ counter, todos })
. 这相当于写作combineReducers({ counter: counter, todos: todos })
。
因此,当您使用时,您...state.list
会因为combineReducers({ list: listReducer })
或simply combineReducers({ list})
了解更多请关注:combineReducers