1
1
import { connect } from 'react-redux' ;
2
+ import PropTypes from 'prop-types' ;
2
3
import React from 'react' ;
3
4
4
- const mapStateToProps = ( state ) => {
5
- // console.log('state对象', state);
6
- return {
7
- value : state . count ,
8
- phone : state . phone ,
9
- }
10
- }
11
-
5
+ const mapStateToProps = ( state ) => ( {
6
+ value : state . count ,
7
+ phone : state . phone ,
8
+ } ) ;
9
+
12
10
const mapDispatchToProps = {
13
- onIncreaseClick : ( ) => {
14
- return {
15
- type : 'increase' ,
16
- count : 10 ,
17
- }
18
- } ,
19
- onDecreaseClick : ( ) => {
20
- return {
21
- type : 'decrease' ,
22
- count : 10 ,
23
- }
24
- } ,
25
- changeMessageCount : ( ) => {
26
- return {
27
- type : 'changeMessageCount' ,
28
- }
29
- } ,
30
- }
11
+ onIncreaseClick : ( ) => ( {
12
+ type : 'increase' ,
13
+ count : 10 ,
14
+ } ) ,
15
+ onDecreaseClick : ( ) => ( {
16
+ type : 'decrease' ,
17
+ count : 10 ,
18
+ } ) ,
19
+ changeMessageCount : ( ) => ( {
20
+ type : 'changeMessageCount' ,
21
+ } ) ,
22
+ } ;
31
23
32
- function Page ( { value, phone, onIncreaseClick, onDecreaseClick, changeMessageCount } ) {
24
+
25
+ function Page ( {
26
+ value, phone, onIncreaseClick, onDecreaseClick, changeMessageCount,
27
+ } ) {
33
28
return (
34
29
< div style = { { marginLeft : 50 } } >
35
30
< h1 > { value } </ h1 >
36
- < button onClick = { onIncreaseClick } > +</ button >
37
- < button style = { { marginLeft : 50 } } onClick = { onDecreaseClick } > -</ button >
38
- < button style = { { marginLeft : 50 } } onClick = { changeMessageCount } > redux异步</ button >
31
+ < button type = "button" onClick = { onIncreaseClick } > +</ button >
32
+ < button type = "button" style = { { marginLeft : 50 } } onClick = { onDecreaseClick } > -</ button >
33
+ < button type = "button" style = { { marginLeft : 50 } } onClick = { changeMessageCount } > redux异步</ button >
39
34
< h2 style = { { marginTop : 20 } } > { phone } </ h2 >
40
35
</ div >
41
- )
36
+ ) ;
42
37
}
43
38
44
- export default connect ( mapStateToProps , mapDispatchToProps ) ( Page ) ;
39
+ Page . propTypes = {
40
+ value : PropTypes . number . isRequired ,
41
+ phone : PropTypes . number . isRequired ,
42
+ onIncreaseClick : PropTypes . func . isRequired ,
43
+ onDecreaseClick : PropTypes . func . isRequired ,
44
+ changeMessageCount : PropTypes . func . isRequired ,
45
+ } ;
46
+
47
+ export default connect ( mapStateToProps , mapDispatchToProps ) ( Page ) ;
0 commit comments