Created
November 17, 2017 04:33
-
-
Save dceddia/15f2f0a9e218698d01f76a8b0ff9c0a0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 from 'react'; | |
import { connect } from 'react-redux'; | |
class Counter extends React.Component { | |
increment = () => { | |
this.props.dispatch({ type: 'INCREMENT' }); | |
} | |
decrement = () => { | |
this.props.dispatch({ type: 'DECREMENT' }); | |
} | |
render() { | |
return ( | |
<div> | |
<h2>Counter</h2> | |
<div> | |
<button onClick={this.decrement}>-</button> | |
<span>{this.props.count}</span> | |
<button onClick={this.increment}>+</button> | |
</div> | |
</div> | |
) | |
} | |
} | |
function mapStateToProps(state) { | |
return { | |
count: state.count | |
}; | |
} | |
export default connect(mapStateToProps)(Counter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment