基于create-react-app的应用程序不适用于redux-saga

问题描述 投票:0回答:0

我正在基于create-react-app的应用程序上工作。 我需要将redux-saga添加到堆栈中,并且不起作用。

我在商店中添加了sagaMiddleware:

import createSagaMiddleware from 'redux-saga';
import sagas from './sagas';

const sagaMiddleware = createSagaMiddleware();
const middlewares = [sagaMiddleware, createDebounce(), thunk, exponentialRetry, routerMiddleware(history)];
const store = createStore(reducer, composeEnhancers(applyMiddleware(...middlewares)));
store.runSaga = sagaMiddleware.run(sagas);

我有一个动作,该动作在componentDidMount上调度。 我可以看到它是在reducer中调度的,reduce也监听这个动作。

我有一个传奇文件:

import { takeLatest } from 'redux-saga/effects';
import { FETCH_TASK } from './types';

export function* fetchTaskById(id) {
  console.log('id', id);
}

export default function*() {
  yield takeLatest(FETCH_TASK, fetchTaskById);
}

我有一个文件,它从一个rootSaga中收集来自不同文件的所有sagas,并导入存储中:

import { fork, all } from 'redux-saga/effects';
import TaskFormSaga from './containers/task-form/sagas';

const sagas = [...TaskFormSaga];

export default function* rootSaga() {
  yield all(sagas.map(fork));
}

从代码角度来看,一切看起来都很好,但是从未调用过fetchTaskById传奇。 另外,如果我在saga的导出默认功能中添加console.log,则它永远不会写在控制台上。

我会暗示可能有什么问题。

create-react-app redux-saga
© www.soinside.com 2019 - 2024. All rights reserved.