我创建了这样的中间件:
export default store => next => action => {
const res = next(action)
console.log("Middleware", action.type)
return res
}
我的商店配置为:
import { createBrowserHistory } from 'history';
import { applyMiddleware, compose, createStore } from 'redux';
import { routerMiddleware } from 'connected-react-router';
import middleware from './middleware'
import rootReducer from './reducers';
export const history = createBrowserHistory();
const defaultState = {};
const composeEnhancers =
typeof window === 'object' &&
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
}) : compose;
const enhancer = composeEnhancers(
applyMiddleware(middleware, routerMiddleware(history)),
);
export const store = createStore(
rootReducer(history),
defaultState,
enhancer
);
我也有一个reducer,并且在日志和调试器中看到,首先调用reducer,然后再调用中间件。关于我配置错误的任何建议吗?
答案 0 :(得分:0)
如果我没记错的话,调用next(action)
时正在调用reducer。将console.log
移到上方,这应该会给您想要的日志顺序。