Skip to content

Instantly share code, notes, and snippets.

@dceddia
Created November 17, 2017 04:33
Show Gist options
  • Save dceddia/15f2f0a9e218698d01f76a8b0ff9c0a0 to your computer and use it in GitHub Desktop.
Save dceddia/15f2f0a9e218698d01f76a8b0ff9c0a0 to your computer and use it in GitHub Desktop.
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