我第一次尝试用configureStore实现redux-saga。以下是我的店:
//LOCAL
import { rootSaga } from "./saga"
import { reducer } from "./reducers"
//GLOBAL
import {configureStore} from "@reduxjs/toolkit"
import createSagaMiddleware from "redux-saga"
import logger from "redux-logger"
//create Middleware
const sagaMiddleware = createSagaMiddleware()
sagaMiddleware.run(rootSaga)
const store = configureStore(
{
reducer: reducer,
middleware: [sagaMiddleware, logger]
}
)
export default store
我得到了以下错误:
Before running a Saga, you must mount the Saga middleware on the Store using applyMiddleware
at Function.sagaMiddleware.run
这是有意义的,因为在将中间件应用于商店之前,我已经运行了中间件。但是,当我将它放在configureStore调用之后时,我得到:
Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
我以前也犯过这个错误,我不相信,因为它似乎只是出现在不同的问题上。我到底在做什么错事?
任何帮助都是感激的,谢谢!
发布于 2022-05-26 01:39:39
我在这里找到了答案:https://stackoverflow.com/a/69242812
I had a similar issue; I fixed this by running npm install react-redux redux . Try it.
这显然与我的代码无关,而是我没有安装正确的软件包。希望有一天这能帮到别人!
https://stackoverflow.com/questions/72385675
复制相似问题