Created
December 7, 2018 05:43
-
-
Save syamjayaraj/5e979ac506e633fb4bb46610cb7ddb01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react' | |
import Button from '../components/Button' | |
import {connect} from 'react-redux' | |
import {incrementCount, decrementCount} from '../actions/index' | |
class CounterComponent extends Component{ | |
handleBtnActionIncrement = () => { | |
this.props.onIncrementClick(this.props.count) | |
} | |
handleBtnActionDecrement = () => { | |
this.props.onDecrementClick(this.props.count) | |
} | |
render() { | |
const {count}=this.props | |
return( | |
<div> | |
<h1>Count: {count}</h1> | |
<Button action={this.handleBtnActionIncrement} buttonTitle = "+" /> | |
<Button action={this.handleBtnActionDecrement} buttonTitle = "-" /> | |
</div> | |
) | |
} | |
} | |
const mapStateToProps = (state) => { | |
return { | |
count: state.counter.count | |
} | |
} | |
const mapDispatchToProps = (dispatch) => { | |
return { | |
onIncrementClick: (count) => { | |
dispatch(incrementCount(count)) | |
}, | |
onDecrementClick: (count) => { | |
if(count !== 0) | |
dispatch(decrementCount(count)) | |
} | |
} | |
} | |
export default connect(mapStateToProps, mapDispatchToProps)(CounterComponent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment