Skip to content

Instantly share code, notes, and snippets.

@cjoecker
Last active March 28, 2020 19:44
Show Gist options
  • Save cjoecker/4d22c93ca3c1842f733a867697200c7a to your computer and use it in GitHub Desktop.
Save cjoecker/4d22c93ca3c1842f733a867697200c7a to your computer and use it in GitHub Desktop.
import React from 'react';
import {useDispatch, useSelector} from "react-redux";
import {CounterActionTypes} from "../services/Counter_Actions";
function Counter() {
const dispatch = useDispatch();
const {counterNumber} = useSelector(state => state.Counter);
return (
<div className="App">
<h1>{counterNumber}</h1>
<button
onClick={(e) => {
dispatch({type: CounterActionTypes.SumCounter})
}}>
Sum + 1
</button>
&nbsp;
<button
onClick={(e) => {
dispatch({type: CounterActionTypes.SubtractCounter})
}}>
Sum - 1
</button>
</div>
);
}
export default Counter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment