Skip to content

Instantly share code, notes, and snippets.

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