-
-
Save Nilanth/4319eaa10945019ced8eda826a8709c3 to your computer and use it in GitHub Desktop.
dispatch
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 { useSelector, useDispatch } from 'react-redux' | |
import { decrement, increment } from './counterSlice' | |
export function Counter() { | |
const count = useSelector((state) => state.counter.value) | |
const dispatch = useDispatch() | |
return ( | |
<div> | |
<div> | |
<button | |
aria-label="Increment value" | |
onClick={() => dispatch(increment())} | |
> | |
Increment | |
</button> | |
<span>{count}</span> | |
<button | |
aria-label="Decrement value" | |
onClick={() => dispatch(decrement())} | |
> | |
Decrement | |
</button> | |
</div> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment