File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -95,23 +95,30 @@ Why don’t we bind action creators to a store right away? This is because of th
95
95
import { Component } from ' react' ;
96
96
import { connect } from ' react-redux' ;
97
97
98
- // Action creators:
99
- import { increment } from ' ../actionsCreators' ;
100
98
// “Dumb” component:
101
99
import Counter from ' ../components/Counter' ;
102
100
101
+ // Action creators:
102
+ import { increment } from ' ../actionsCreators' ;
103
+
103
104
// Which part of the Redux global state does our component want to receive as props?
104
105
function mapState (state ) {
105
106
return {
106
107
counter: state .counter
107
108
};
108
109
}
109
110
110
- // First argument tells which state fields it’s interested in.
111
- // Second argument tells which action creators to bind and inject.
112
- // You may also pass a `dispatch` => Object function as a second argument.
111
+ // Which action creators does it want to receive by props?
112
+ function mapDispatch (dispatch ) {
113
+ return {
114
+ increment : () => dispatch (increment ())
115
+ };
116
+ }
117
+
118
+ export default connect (mapState, mapDispatch)(CounterContainer);
113
119
114
- export default connect (mapState, { increment })(CounterContainer);
120
+ // You can also pass an object instead of defining `mapDispatch`:
121
+ // export default connect(mapState, CounterActionCreators)(CounterContainer);
115
122
```
116
123
117
124
Whether to put ` connect() ` call in the same file as the “dumb” component, or separately, is up to you.
You can’t perform that action at this time.
0 commit comments