有人可以帮忙吗,
Error: Before running a Saga, you must mount the Saga middleware on the Store using applyMiddleware
挂载 sagaMiddleware 仍然在页面上抛出错误使用 saga Middleware
Store Js
将 redux-saga 添加到 Store
import { createStore, applyMiddleware, compose } from "redux";
import { persistStore } from "redux-persist";
import createSagaMiddleware from 'redux-saga'
import {fetchCollectionsStart} from './shop/shop.sagas'
import logger from "redux-logger";
import rootReducer from "./root-reducer";
const sagaMiddleware = createSagaMiddleware();
const middlewares = [sagaMiddleware];
if (process.env.NODE_ENV === "development") {
middlewares.push(logger);
}
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(...middlewares,sagaMiddleware)
// other store enhancers if any
);
sagaMiddleware.run(fetchCollectionsStart);
export const store = createStore(rootReducer, enhancer);
export const persistor = persistStore(store);
创建此 saga 以在安装组件后获取集合
Sagas.js
import {takeEvery} from 'redux-saga/effects';
import ShopActionTypes from './shop.types';
export function* fetchCollectionsAsync(){
yield console.log('Good');
}
export function* fetchCollectionsStart(){
yield takeEvery(ShopActionTypes.FETCH_COLLECTIONS_START,
fetchCollectionsAsync );
}