这个Redux applyMiddleware有什么问题,因为它只能与一个

时间:2019-07-07 13:17:37

标签: react-redux

我学习了React Redux,如果我在index.js中有一个middleware函数并将其导入到configureStore.js中,那么一切将如下所示:

const middlewares = [forbiddenWordsMiddleware, thunk]
const store = createStore(
  reduce,
  storeEnhancers(applyMiddleware(...middlewares))
);
export default store;

当我像这样添加另一个middlewaregetDataMiddleware时:

const middlewares = [forbiddenWordsMiddleware, getDataMiddleware, thunk]
const store = createStore(
  reduce,
  storeEnhancers(applyMiddleware(...middlewares))
);
export default store;

我在另一个禁止的WordsMiddleware中收到错误,如下所示:

TypeError: next is not a function
(anonymous function)
L:/react/redux-tutorial/src/js/middleware/index.js:19
  16 |                     return dispatch(addBadWword(foundWord));
  17 |                 }
  18 |             }
> 19 |             return next(action);
  20 |         };
  21 |     };
  22 | }

我认为功能已正确导出/导入 我添加了一张显示文件和错误的图片:

can

1 个答案:

答案 0 :(得分:1)

getDataMiddleware第二个函数接收next中间件的分派方法。似乎您误将其命名为dispatch