2018-05-07 13:03:54 +00:00
|
|
|
import React, {Component} from 'react'
|
|
|
|
import { connect } from 'react-redux'
|
2018-05-15 07:49:07 +00:00
|
|
|
import { incrementCount, decrementCount, resetCount } from '../store'
|
2018-05-07 13:03:54 +00:00
|
|
|
|
2018-05-15 07:49:07 +00:00
|
|
|
class Counter extends Component {
|
|
|
|
increment = () => {
|
2018-05-07 13:03:54 +00:00
|
|
|
const {dispatch} = this.props
|
2018-05-15 07:49:07 +00:00
|
|
|
dispatch(incrementCount())
|
|
|
|
}
|
|
|
|
|
|
|
|
decrement = () => {
|
|
|
|
const {dispatch} = this.props
|
|
|
|
dispatch(decrementCount())
|
|
|
|
}
|
|
|
|
|
|
|
|
reset = () => {
|
|
|
|
const {dispatch} = this.props
|
|
|
|
dispatch(resetCount())
|
2018-05-07 13:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { count } = this.props
|
|
|
|
return (
|
|
|
|
<div>
|
2018-05-15 07:49:07 +00:00
|
|
|
<h1>Count: <span>{count}</span></h1>
|
|
|
|
<button onClick={this.increment}>+1</button>
|
|
|
|
<button onClick={this.decrement}>-1</button>
|
|
|
|
<button onClick={this.reset}>Reset</button>
|
2018-05-07 13:03:54 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
const {count} = state
|
|
|
|
return {count}
|
|
|
|
}
|
|
|
|
|
2018-05-15 07:49:07 +00:00
|
|
|
export default connect(mapStateToProps)(Counter)
|