Last active
July 24, 2019 23:13
-
-
Save maximiliangonzalez/f09732f77e7748076cd38f65e63870fd to your computer and use it in GitHub Desktop.
React component connecting to the Redux store WITHOUT using React Redux hooks
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 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