Created
September 1, 2017 04:33
-
-
Save DobrinGanev/b7f5a6e12e4b09e7056bb48562130f98 to your computer and use it in GitHub Desktop.
redux last Action
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
const reducer = ((state = 0, action) => { | |
switch (action.type) { | |
case 'INCREMENT': return state + 1 | |
case 'DECREMENT': return state - 1 | |
default: return state | |
} | |
}) | |
const initialState = { | |
count: 0 | |
} | |
const lastAction = (state = null, action) => { | |
return action; | |
} | |
const rootReducer = combineReducers({ | |
reducer, | |
lastAction | |
}); | |
const store = createStore(rootReducer) | |
store.subscribe(() => { | |
console.log(store.getState().lastAction)// last action | |
}) | |
store.dispatch({ type: 'INCREMENT' }) | |
store.dispatch({ type: 'DECREMENT' }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment