Last active
April 12, 2019 14:20
-
-
Save hansott/91421362756cbae4ccdf1c28a8fca846 to your computer and use it in GitHub Desktop.
redux-logger for useReducer
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
import { logger } from "./logger"; | |
import React, { useReducer } from "react"; | |
const reducer = (state, action) => state; | |
const initialState = {}; | |
export const Component = () => { | |
const [state, dispatch] = useReducer(logger(reducer), initialState); | |
return <div></div>; | |
} |
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
export const logger = (reducer) => { | |
return (state, action) => { | |
console.log("%cPrevious State:", "color: #9E9E9E; font-weight: 700;", state); | |
console.log("%cAction:", "color: #00A7F7; font-weight: 700;", action); | |
console.log("%cNext State:", "color: #47B04B; font-weight: 700;", reducer(state, action)); | |
return reducer(state, action); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment