中间件就是非业务的技术类组件。它介于底层逻辑与业务之间,相当于中介的作用。
const logger = (store) => (next) => (action) => {console.log('dispatch--->', action)let result = next(action) //加载下一个中间件console.log('next state--->', store.getState())return result}const throwError = (store) => (next) => (action) => {try {next(action)} catch (e) {console.log('error--->', e)}}const Store = createStore(reducer, {}, applyMiddleware(logger, throwError))
redux-logger
记录 action 动作并在控制台打印
redux-thunk
处理异步的中间件
redux-sage
Effect 里面包含描述副作用的信息,可以通过 yield 传递厨 sagaMiddleware 执行
