首页 > 代码库 > Middleware

Middleware

redux中间件就是对dispatch进行处理,dispatch接收action creator后先进行处理后再讲action传给reducer

技术分享

使用方法:

const createStoreWithMiddleware = applyMiddleware(
  thunkMiddleware,
  loggerMiddleware
)(createStore);
store
= createStoreWithMiddleware(rootReducer, initialState);

执行过程:

技术分享

编写middleware:

const customMiddleware = store => next => action => {
  if(action.type !== ‘custom‘) return next(action)
  //do stuff!
}

 

Middleware