Last active
July 24, 2019 20:32
-
-
Save maximiliangonzalez/68a34b96b0c588f2b1d85cbfe10f8fe5 to your computer and use it in GitHub Desktop.
React functional component connecting to Redux store using useSelector hook (still using connect for mapDispatchToProps)
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 {useSelector, connect} from 'react-redux'; | |
import * as actions from '../actions/actions'; | |
const App = props => { | |
const {increment, decrement} = props; | |
const count = useSelector(store => store.count); | |
return ( | |
<div> | |
<h1>The count is {count}</h1> | |
<button onClick={() => increment(count)}>+</button> | |
<button onClick={() => decrement(count)}>-</button> | |
</div> | |
); | |
} | |
const mapDispatchToProps = dispatch => ({ | |
increment: count => dispatch(actions.increment(count)), | |
decrement: count => dispatch(actions.decrement(count)) | |
}); | |
export default connect(null, mapDispatchToProps)(App); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment