Skip to content

Commit 14b5cff

Browse files
committed
Update README.md
1 parent 59f543b commit 14b5cff

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,30 @@ Why don’t we bind action creators to a store right away? This is because of th
9595
import { Component } from 'react';
9696
import { connect } from 'react-redux';
9797

98-
// Action creators:
99-
import { increment } from '../actionsCreators';
10098
// “Dumb” component:
10199
import 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?
104105
function 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

117124
Whether to put `connect()` call in the same file as the “dumb” component, or separately, is up to you.

0 commit comments

Comments
 (0)