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