Created
August 19, 2019 11:28
-
-
Save honzabrecka/b30bb21315f810aafc357a7e8abf1886 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 withLogger = (reducer) => (state, action) => { | |
const boldStyle = 'font-weight:bold'; | |
console.groupCollapsed(`%caction %c${action.type}`, 'color:#CCC', boldStyle); | |
console.log('%cprev state', `${boldStyle};color:#9E9E9E`, state); | |
console.log('%caction ', `${boldStyle};color:#03A9F4`, action); | |
const after = reducer(state, action); | |
console.log('%cnext state', `${boldStyle};color:#4CAF50`, after); | |
console.groupEnd(); | |
return after; | |
}; | |
// use | |
// const [state, dispatch] = useReducer(withLogger(reducer), initialState); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment