我可以使用require获得createSagaMiddleware吗?

时间:2019-04-09 21:35:06

标签: node.js redux-saga

我正在尝试在将从命令行运行的节点应用程序中使用run sagas:node app.js

我不能使用导入,所以我试图使用require来获取createSagaMiddleware:

const sagaMiddleware = createSagaMiddleware()

我收到此错误:

“ TypeError:createSagaMiddleware不是函数”

可以像这样使用佐​​贺吗?

const { createStore, combineReducers, applyMiddleware } = require("redux");
const createSagaMiddleware  = require("redux-saga");
const {  take } = require("redux-saga/effects");

const sagaMiddleware = createSagaMiddleware();

const reducer = state => state;

const store = createStore(
    reducer,
    applyMiddleware(sagaMiddleware)
);

function* watcherSaga() {
    yield take("START");
    yield //do stuff
}

sagaMiddleware.run(watcherSaga)

store.dispatch({type: 'START'})

1 个答案:

答案 0 :(得分:0)

尝试一下:

const createSagaMiddleware  = require("redux-saga").default;