Created
September 27, 2019 12:16
-
-
Save newbornfrontender/6697979b319e3433882f5a7542b8e890 to your computer and use it in GitHub Desktop.
redux counter
This file contains hidden or 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 { createStore } from 'redux'; | |
const increment = () => ({ | |
type: 'INCREMENT', | |
}); | |
const decrement = () => ({ | |
type: 'DECREMENT', | |
}); | |
function counter(state = 0, action) { | |
switch (action.type) { | |
case 'INCREMENT': | |
return state + 1; | |
case 'DECREMENT': | |
return state - 1; | |
default: | |
return state; | |
} | |
} | |
const store = createStore(counter); | |
store.subscribe(() => console.log(store.getState())); | |
store.dispatch(increment()); | |
store.dispatch(decrement()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment