Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const logEnhancer = (createStore) => (reducer, initialState, enhancer) => {
// Do stuff like wrap the reducer in a higher-order function.
const reducerWithConsoleLogs = (previousState, action) => {
const nextState = reducer(previousState, action);
console.log({ action, previousState, nextState });
return nextState;
};
return createStore(reducerWithConsoleLogs, initialState, enhancer);
};
const monitorMiddleware = (store) => (next) => (action) => {
const start = performance.now();
next(action);
const end = performance.now();
const diff = round(end - start);
console.log("reducer process time:", diff);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment