我正在尝试在将从命令行运行的节点应用程序中使用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'})
答案 0 :(得分:0)
尝试一下:
const createSagaMiddleware = require("redux-saga").default;