Skip to content

Instantly share code, notes, and snippets.

@elshanx
Last active November 24, 2021 15:01
Show Gist options
  • Save elshanx/136beb4827e8e5dfd1ed328a7cddb6ec to your computer and use it in GitHub Desktop.
Save elshanx/136beb4827e8e5dfd1ed328a7cddb6ec to your computer and use it in GitHub Desktop.
custom redux logger middleware with toggle functionality
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