Counter.js 563 B

1234567891011121314151617181920212223
  1. import { useDispatch, useSelector } from "react-redux";
  2. import {inc, dec, rnd} from '../actions';
  3. const Counter = () => {
  4. const counter = useSelector(state => state.counter);
  5. const dispatch = useDispatch();
  6. return (
  7. <>
  8. <div > {counter} </div>
  9. <button onClick={() => dispatch(dec())} > - </button>
  10. <button onClick={() => dispatch(inc())} > + </button>
  11. <button onClick={() => dispatch(rnd())} > rnd </button>
  12. </>
  13. )
  14. }
  15. export default Counter;