Reactjs Redux中间件在reducer之后被调用
我创建了如下中间件:Reactjs Redux中间件在reducer之后被调用,reactjs,redux,react-redux,redux-middleware,Reactjs,Redux,React Redux,Redux Middleware,我创建了如下中间件: export default store => next => action => { const res = next(action) console.log("Middleware", action.type) return res } 我的商店配置是: import { createBrowserHistory } from 'history'; import { applyMiddleware, compose, c
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首先被调用,然后是中间件。关于我配置的错误有什么建议吗?如果我没记错的话,在调用
next(action)
时正在调用reducer。将您的控制台移动到上面。log
应该会给出您想要的日志顺序。该死-您认为它在返回时被触发是对的