我学习了React Redux,如果我在index.js中有一个middleware
函数并将其导入到configureStore.js中,那么一切将如下所示:
const middlewares = [forbiddenWordsMiddleware, thunk]
const store = createStore(
reduce,
storeEnhancers(applyMiddleware(...middlewares))
);
export default store;
当我像这样添加另一个middleware
和getDataMiddleware
时:
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 | }
我认为功能已正确导出/导入 我添加了一张显示文件和错误的图片:
答案 0 :(得分:1)
getDataMiddleware
第二个函数接收next
中间件的分派方法。似乎您误将其命名为dispatch
。