2018-12-17 16:34:32 +00:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import { connect } from 'react-redux'
|
2018-05-16 08:47:12 +00:00
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
import { increment, decrement, reset } from '../actions'
|
2018-05-16 08:47:12 +00:00
|
|
|
|
|
|
|
class Counter extends Component {
|
|
|
|
increment = () => {
|
|
|
|
this.props.dispatch(increment())
|
|
|
|
}
|
|
|
|
|
|
|
|
decrement = () => {
|
|
|
|
this.props.dispatch(decrement())
|
|
|
|
}
|
|
|
|
|
|
|
|
reset = () => {
|
|
|
|
this.props.dispatch(reset())
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2018-12-17 16:34:32 +00:00
|
|
|
const { count } = this.props
|
2018-05-16 08:47:12 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<style jsx>{`
|
|
|
|
div {
|
|
|
|
padding: 0 0 20px 0;
|
|
|
|
}
|
|
|
|
`}</style>
|
|
|
|
<h1>
|
|
|
|
Count: <span>{count}</span>
|
|
|
|
</h1>
|
|
|
|
<button onClick={this.increment}>+1</button>
|
|
|
|
<button onClick={this.decrement}>-1</button>
|
|
|
|
<button onClick={this.reset}>Reset</button>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
const mapStateToProps = ({ count }) => ({ count })
|
2018-05-16 08:47:12 +00:00
|
|
|
export default connect(mapStateToProps)(Counter)
|