File tree 1 file changed +32
-7
lines changed
1 file changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -20,15 +20,40 @@ const mapStateToProps = (state) => ({
20
20
count : state . count
21
21
} )
22
22
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
+ )
30
46
}
31
47
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
+
32
57
export default connect ( mapStateToProps , mapDispatchToProps ) ( Counter )
33
58
34
59
/*
You can’t perform that action at this time.
0 commit comments