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
9595import { Component } from ' react' ;
9696import { connect } from ' react-redux' ;
9797
98- // Action creators:
99- import { increment } from ' ../actionsCreators' ;
10098// “Dumb” component:
10199import Counter from ' ../components/Counter' ;
102100
101+ // Action creators:
102+ import { increment } from ' ../actionsCreators' ;
103+
103104// Which part of the Redux global state does our component want to receive as props?
104105function mapState (state ) {
105106 return {
106107 counter: state .counter
107108 };
108109}
109110
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);
113119
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);
115122```
116123
117124Whether 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