Skip to content

Instantly share code, notes, and snippets.

@maximiliangonzalez
Last active July 24, 2019 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximiliangonzalez/f09732f77e7748076cd38f65e63870fd to your computer and use it in GitHub Desktop.
Save maximiliangonzalez/f09732f77e7748076cd38f65e63870fd to your computer and use it in GitHub Desktop.
React component connecting to the Redux store WITHOUT using React Redux hooks
import React from 'react';
import {connect} from 'react-redux';
import * as actions from '../actions/actions';
class App extends React.Component {
constructor(props) {
super(props);
}
render() {
const {count, increment, decrement} = this.props;
return (
<div>
<h1>The count is {count}</h1>
<button onClick={() => increment(count)}>+</button>
<button onClick={() => decrement(count)}>-</button>
</div>
);
}
}
const mapStateToProps = store => ({
count: store.count
});
const mapDispatchToProps = dispatch => ({
increment: count => dispatch(actions.increment(count)),
decrement: count => dispatch(actions.decrement(count))
});
export default connect(mapStateToProps, mapDispatchToProps)(App);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment