Skip to content

Instantly share code, notes, and snippets.

@avin-kavish
Created March 30, 2020 10:29
Show Gist options
  • Save avin-kavish/91d37242c321512c2a8d0520c2851f0a to your computer and use it in GitHub Desktop.
Save avin-kavish/91d37242c321512c2a8d0520c2851f0a to your computer and use it in GitHub Desktop.
const incrementCounter = () => {
type: 'INCREMENT',
}
const initialState = {
counter: 0
}
function reducer(state = initialState, action = {}) {
switch(action.type) {
case 'INCREMENT':
return { ...state, counter: state.counter + 1 }
default:
return state
}
}
function MyComponent() {
const counter = useSelector(s => s.feature.counter)
const dispatch = useDispatch()
return (
<>
<div>{counter}</div>
<button onClick={() => dispatch(incrementCounter())} />
</>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment