首页 > 解决方案 > Redux-saga 没有在我的 reactJS 应用程序中运行

问题描述

我有我非常简单的测试传奇:

 export function* helloSaga() {
    console.log('Hello Sagas!')
}

我是这样称呼它的:

 import reducer from "./Redux/rootReducer";
import {helloSaga} from "./Redux/Sagas/saga";

const sagaMiddleware = createSagaMiddleware();
export const store = createStore(
    reducer,
    applyMiddleware(sagaMiddleware),
    window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() // chrome devtools thing
);

sagaMiddleware.run(helloSaga())

但我得到了错误× Error: runSaga(options, saga, ...args): saga argument must be a Generator function!。请问有什么建议吗?

标签: reactjsredux

解决方案


看起来您传递了生成器函数的结果而不是函数本身,如下所示:

sagaMiddleware.run(helloSaga)

推荐阅读