我正在学习 redux-saga 并尝试在我的 React 应用程序中进行设置,但我遇到了这个错误:
“redux”包中缺少“./saga”说明符
产品.saga.js
import { takeLatest, all, call, put } from "redux-saga/effects";
import { getAllProducts } from "./product.utils";
export function* fetchProductsAsync() {
try {
const apiResponse = yield call(getAllProducts)
yield put(fetchProductsSuccess(apiResponse))
} catch (error) {
yield put(fetchProductsFailed(error))
}
}
export function* onFetchProducts() {
yield takeLatest(
ProductActionTypes.GET_ALL,
fetchProductsAsync
)
}
export function* productsSaga() {
yield all([
call(onFetchProducts)
])
}
root-saga.js
import { all, call } from 'redux-saga/effects'
import { productsSaga } from './products/product.saga'
export function* rootSaga() {
yield all([
call(productsSaga)
])
}
store.js
import { createStore, applyMiddleware } from 'redux'
import { persistStore } from 'redux-persist'
import { logger } from 'redux-logger'
import createSagaMiddleware from 'redux/saga'
import { rootSaga } from './root-saga'
import rootReducer from './root-reducer'
const sagaMiddleware = createSagaMiddleware()
const middlewares = [logger, sagaMiddleware]
export const store = createStore(rootReducer, applyMiddleware(...middlewares))
sagaMiddleware.run(rootSaga)
export const persistor = persistStore(store)
export default { store, persistor }
尝试在 redux 和 redux-saga 上重新运行
npm install
但仍然不起作用。
您正在尝试从
'redux/saga'
导入,它绝对不存在。您是否想从 'redux-saga'
导入?