使用 configureStore 实现 Redux-Saga

Implementing Redux-Saga with configureStore

我第一次尝试使用 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

我以前遇到过这个错误,但我不相信,因为它似乎只是针对各种不同的问题突然出现。那么我到底做错了什么?

感谢任何帮助,谢谢!

我在这里找到了答案:

I had a similar issue; I fixed this by running npm install react-redux redux . Try it.

这显然与我的代码无关,而是我没有安装正确的软件包。希望有一天这可以帮助其他人!