Created
March 30, 2020 10:29
-
-
Save avin-kavish/91d37242c321512c2a8d0520c2851f0a to your computer and use it in GitHub Desktop.
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
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