|
@@ -1,11 +1,18 @@
|
1
|
1
|
import * as React from 'react'
|
2
|
2
|
import { connect } from 'react-redux'
|
|
3
|
+import { bindActionCreators } from 'redux';
|
|
4
|
+import * as actions from '../../redux/action'
|
3
|
5
|
import DecreaseBtn from '../../component/decreaseBtn'
|
4
|
6
|
import IncreaseBtn from '../../component/increaseBtn'
|
5
|
7
|
import NowValue from '../../component/showValue'
|
6
|
8
|
import './index.less'
|
7
|
9
|
|
8
|
10
|
class Counter extends React.Component<any, any> {
|
|
11
|
+ public componentDidMount () {
|
|
12
|
+ console.log('this.props',this.props)
|
|
13
|
+ let { count } = this.props
|
|
14
|
+ this.props.actions.saveCount(--count)
|
|
15
|
+ }
|
9
|
16
|
public handleDecreaseCB = () => {
|
10
|
17
|
let { count } = this.props
|
11
|
18
|
this.props.saveCount({ count: --count })
|
|
@@ -40,7 +47,8 @@ class Counter extends React.Component<any, any> {
|
40
|
47
|
|
41
|
48
|
export default connect(
|
42
|
49
|
(state: any) => ({ count: state.count }),
|
43
|
|
- {
|
44
|
|
- saveCount: (payload: any) => ({ type: 'SAVECOUNT', payload }),
|
45
|
|
- }
|
|
50
|
+ (dispatch: any) => ({ actions: bindActionCreators(actions, dispatch) })
|
|
51
|
+ // {
|
|
52
|
+ // saveCount: (payload: any) => ({ type: 'SAVECOUNT', payload }),
|
|
53
|
+ // }
|
46
|
54
|
)(Counter)
|