Skip to content

Commit 793d332

Browse files
committed
shape of state in mapStateToProps
1 parent bfbf84b commit 793d332

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Redux/mapStateToProps-how-exactly-it-gets-the-state-from-reducers.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default combineReducers({
8181
});
8282
```
8383

84-
See, that for each of the reducers I am returning the state object specifying a single variable as the key. So for the tidalReducers, I am returning the key as 'tides'
84+
See, that for each of the reducers, I am returning the state object specifying a single variable as the key. So for the tidalReducers, I am returning the key as 'tides'
8585

8686
#### And thats the most important point
8787

@@ -122,3 +122,11 @@ export default connect(
122122
mapDispatchToProps
123123
)(withStyles(styles)(TidalsList));
124124
```
125+
126+
With respect to the above here's what the [official documentation](https://redux.js.org/recipes/structuring-reducers/using-combinereducers#defining-state-shape) says
127+
128+
**Defining State Shape**
129+
130+
There are two ways to define the initial shape and contents of your store's state. First, the createStore function can take preloadedState as its second argument. This is primarily intended for initializing the store with state that was previously persisted elsewhere, such as the browser's localStorage. The other way is for the root reducer to return the initial state value when the state argument is undefined. These two approaches are described in more detail in Initializing State, but there are some additional concerns to be aware of when using combineReducers.
131+
132+
**combineReducers takes an object full of slice reducer functions, and creates a function that outputs a corresponding state object with the same keys. This means that if no preloaded state is provided to createStore, the naming of the keys in the input slice reducer object will define the naming of the keys in the output state object.**

0 commit comments

Comments
 (0)