You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/using-react-redux/connect-extracting-data-with-mapStateToProps.md
+6-3Lines changed: 6 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,9 @@ This function should be passed as the first argument to `connect`, and will be c
28
28
29
29
### Arguments
30
30
31
+
1. **`state`**
32
+
2. **`ownProps` (optional)**
33
+
31
34
#### `state`
32
35
33
36
The first argument to a `mapStateToProps` function is the entire Redux store state (the same value returned by a call to `store.getState()`). Because of this, the first argument is traditionally just called `state`. (While you can give the argument any name you want, calling it `store` would be incorrect - it's the "state value", not the "store instance".)
@@ -131,13 +134,13 @@ To summarize the behavior of the component wrapped by `connect` with `mapStateTo
| `mapStateToProps` runs when: | store `state` changes | store `state` changes <br /> or <br />any field of `ownProps` is different |
137
+
| `mapStateToProps` runs when: | store `state` changes | store `state` changes <br /> or <br />any field of `ownProps` is different |
135
138
| component re-renders when: | any field of `stateProps` is different | any field of `stateProps` is different <br /> or <br /> any field of `ownProps` is different |
136
139
137
140
138
141
### Only Return New Object References If Needed
139
142
140
-
React-Redux does shallow comparisons to see if the `mapState` results have changed. It’s easy to accidentally return new object or array references every time, which would cause your component to re-render even if the data is actually the same.
143
+
React-Redux does shallow comparisons to see if the `mapStateToProps` results have changed. It’s easy to accidentally return new object or array references every time, which would cause your component to re-render even if the data is actually the same.
141
144
142
145
Many common operations result in new object or array references being created:
143
146
@@ -147,7 +150,7 @@ Many common operations result in new object or array references being created:
147
150
- Copying values with `Object.assign`
148
151
- Copying values with the spread operator `{ ...oldState, ...newData }`
149
152
150
-
Put these operations in [memoized selector functions]() to ensure that they only run if the input values have changed. This will also ensure that if the input values _haven't_ changed, `mapState` will still return the same result values as before, and `connect` can skip re-rendering.
153
+
Put these operations in [memoized selector functions]() to ensure that they only run if the input values have changed. This will also ensure that if the input values _haven't_ changed, `mapStateToProps` will still return the same result values as before, and `connect` can skip re-rendering.
0 commit comments