今天 webpack 打包的时候遇到问题:
代码语言:javascript复制It looks like you are passing several store enhancers to createStore(). This is not supported. Instead, compose them together to a single function
代码语言:javascript复制const store = createStore(
Reducer, /* reducer */
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(), /* preloadedState */
applyMiddleware(thunk) /* enhancer(middleware) */
);
以前 createStore
集成 redux-devtool
的时候提供 3 个参数, 现在需要将后面的 middleware 全部包裹起来:
import { createStore, compose, applyMiddleware } from 'redux';
// 加一行
const composeEnhancer = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
// 然后使用 composeEnhancer 包裹之前的 Middleware 然后传递给第二个参数。const store = createStore(
Reducer, /* reducer */
composeEnhancer(
applyMiddleware(thunk), /* enhancer(middleware) */
)
);