Skip to content

Instantly share code, notes, and snippets.

@Nilanth

Nilanth/.jsx Secret

Created July 17, 2021 17:12
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 Nilanth/4319eaa10945019ced8eda826a8709c3 to your computer and use it in GitHub Desktop.
Save Nilanth/4319eaa10945019ced8eda826a8709c3 to your computer and use it in GitHub Desktop.
dispatch
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