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!
}

 

posted on 2017-07-12 14:12  高石石石  阅读(150)  评论(0)    收藏  举报

导航