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/1162ca54acef485c419a44af8d20715e to your computer and use it in GitHub Desktop.
Save maximiliangonzalez/1162ca54acef485c419a44af8d20715e to your computer and use it in GitHub Desktop.
React component connecting to Redux store without hooks, converted into a functional component
import React from 'react';
import {connect} from 'react-redux';
import * as actions from '../actions/actions';
const App = props => {
const {count, increment, decrement} = 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