Skip to content

Instantly share code, notes, and snippets.

@honzabrecka
Created August 19, 2019 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save honzabrecka/b30bb21315f810aafc357a7e8abf1886 to your computer and use it in GitHub Desktop.
Save honzabrecka/b30bb21315f810aafc357a7e8abf1886 to your computer and use it in GitHub Desktop.
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