Last active
August 9, 2020 01:28
-
-
Save LambertSchulze/22daaf3c5feb65f0a60c5718787088ab to your computer and use it in GitHub Desktop.
Redux Counter Example
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 INCREMENT = 'INCREMENT'; | |
const DECREMENT = 'DECREMENT'; | |
const counterReducer = (state = 0, action) => { | |
switch(action.type) { | |
case INCREMENT: | |
return (state += 1); | |
case DECREMENT: | |
return (state -= 1); | |
default: return 0; | |
}; | |
}; | |
const incAction = () => {return {type: INCREMENT}}; | |
const decAction = () => {return {type: DECREMENT}}; | |
const store = Redux.createStore(counterReducer); | |
//store.dispatch(incAction()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of a counter done with Redux: