Last active
November 24, 2021 15:01
-
-
Save elshanx/136beb4827e8e5dfd1ed328a7cddb6ec to your computer and use it in GitHub Desktop.
custom redux logger middleware with toggle functionality
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 type { Middleware } from 'redux' | |
import { logger } from 'redux-logger' | |
const customLogger: Middleware = (api) => (next) => (action) => { | |
if (window.__REDUX_LOGGER__) return logger(api)(next)(action) | |
return next(action) | |
} | |
export default customLogger | |
// and in_app.ts | |
if (typeof window !== 'undefined') { | |
window.__REDUX_LOGGER__ = true | |
window.document.body.addEventListener('keydown', e => { | |
if (e.altKey && e.key == 'p') { | |
window.__REDUX_LOGGER__ = !window.__REDUX_LOGGER__ | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment