安装 redux-saga 后创建商店时出现 redux store 错误

redux store Error while creating store after installing redux-saga

我想在我的项目中使用 redux-saga,当我在 store.js 文件中进行更改时安装 redux-saga 后出现错误

Error: It looks like you are passing several store enhancers to createStore(). This is not supported. Instead, compose them together to a single function.

# store.js                     
import { createStore, applyMiddleware, compose } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import thunk from 'redux-thunk';
import rootReducer from './reducers'
import createSagaMiddleware from 'redux-saga';
import rootSaga from './actions/sagas';


const sagaMiddleware = createSagaMiddleware();

const composeEnhancers =
  typeof window === 'object' &&
  window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?   
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
      // Specify extension’s options like name, actionsBlacklist, actionsCreators, serialize...
    }) : compose;


const enhancer = composeEnhancers(
  applyMiddleware(sagaMiddleware)
);



const initialState = {};

const middleware = [thunk];

const store = createStore(
  rootReducer,
  initialState,
  enhancer,
  composeWithDevTools(applyMiddleware(...middleware))
);
  


sagaMiddleware.run(rootSaga);
export default store; 

我不太了解商店。请看看你是否可以提供帮助。

你正在编写你的 devtools 和中间件两次,只使用两者之一。

const store = createStore(
  rootReducer,
  initialState,
// either this line
  enhancer,
// or this line
  composeWithDevTools(applyMiddleware(...middleware))
);

此外,仅供参考:这是一种相当过时的 redux 风格。如果你现在正在学习 redux 并遵循这种方法,你将编写很多不必要的样板文件。请按照 the official redux documentation 上的官方 redux 教程,而不是您现在正在学习的任何教程。