2018-12-17 16:34:32 +00:00
|
|
|
import React, { Component } from 'react'
|
2018-01-31 09:40:32 +00:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
|
import { addCount } from '../lib/store'
|
|
|
|
|
|
|
|
class AddCount extends Component {
|
|
|
|
add = () => {
|
|
|
|
this.props.addCount()
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { count } = this.props
|
|
|
|
return (
|
|
|
|
<div>
|
2018-12-17 16:34:32 +00:00
|
|
|
<h1>
|
|
|
|
AddCount: <span>{count}</span>
|
|
|
|
</h1>
|
2018-01-31 09:40:32 +00:00
|
|
|
<button onClick={this.add}>Add To Count</button>
|
|
|
|
<style jsx>{`
|
|
|
|
h1 {
|
|
|
|
font-size: 20px;
|
|
|
|
}
|
|
|
|
div {
|
|
|
|
padding: 0 0 20px 0;
|
|
|
|
}
|
|
|
|
`}</style>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = ({ count }) => ({ count })
|
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
const mapDispatchToProps = dispatch => {
|
2018-01-31 09:40:32 +00:00
|
|
|
return {
|
|
|
|
addCount: bindActionCreators(addCount, dispatch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(AddCount)
|