Skip to content

Instantly share code, notes, and snippets.

@maximiliangonzalez
Last active July 24, 2019 20:31
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/aa2a308bb371c5819bd198a29060ed50 to your computer and use it in GitHub Desktop.
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?)
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