I have 2 reducers that are combined in a Root Reducer, and used in a store. First reducer 'AllTracksReducer" is supposed to return an object and the second 'FavoritesReducer' an array.
When I create a container component and a mapStateToProps method in connect, for some reason the returned state of the store is an object with 2 reducer objects which hold data, and not just an object containing correposding data, as expected.
function mapStateToProps(state) {
debugger:
console.dir(state)
//state shows as an object with 2 properties, AllTracksReducer and FavoritesReducer.
return {
data: state.AllTracksReducer.data,
isLoading: state.AllTracksReducer.isLoading
}
}
export default connect(mapStateToProps)(AllTracksContainer);
so, in mapStateToProps, to get to the right state property, i have to say state.AllTracksReducer.data... But I was expecting the data to be available directly on the state object?
combineReducers
does. it maps your reducer functions to their own keys on state. otherwise you would certainly have collisions as you add reducers in your app. Is this a problem? – azium Feb 3 '17 at 18:01