Skip to content

Commit 0b60c25

Browse files
Dispatching using bindactioncreators & as actions object
1 parent e88afe1 commit 0b60c25

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

src/components/counter.js

+32-7
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,40 @@ const mapStateToProps = (state) => ({
2020
count: state.count
2121
})
2222

23-
const mapDispatchToProps = (dispatch) => {
24-
return {
25-
increment: () => dispatch(increment()),
26-
decrement: () => dispatch(decrement()),
27-
incrementAsync: () => dispatch(incrementAsync()),
28-
decrementAsync: () => dispatch(decrementAsync())
29-
}
23+
// Way 1
24+
// mapDispatchToProps as function
25+
// const mapDispatchToProps = (dispatch) => {
26+
// return {
27+
// increment: () => dispatch(increment()),
28+
// decrement: () => dispatch(decrement()),
29+
// incrementAsync: () => dispatch(incrementAsync()),
30+
// decrementAsync: () => dispatch(decrementAsync())
31+
// }
32+
// }
33+
34+
// Way 2
35+
// Using bind action creators
36+
function mapDispatchToProps (dispatch) {
37+
return bindActionCreators(
38+
{
39+
increment,
40+
decrement,
41+
incrementAsync,
42+
decrementAsync
43+
},
44+
dispatch
45+
)
3046
}
3147

48+
// Way 3
49+
// connect will automatically call bindActionCreators for you internally
50+
// const mapDispatchToProps = {
51+
// increment,
52+
// decrement,
53+
// incrementAsync,
54+
// decrementAsync
55+
// }
56+
3257
export default connect(mapStateToProps, mapDispatchToProps)(Counter)
3358

3459
/*

0 commit comments

Comments
 (0)