首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用configureStore实现Redux-Saga

用configureStore实现Redux-Saga
EN

Stack Overflow用户
提问于 2022-05-26 01:22:03
回答 1查看 737关注 0票数 0

我第一次尝试用configureStore实现redux-saga。以下是我的店:

代码语言:javascript
运行
复制
//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

我得到了以下错误:

代码语言:javascript
运行
复制
Before running a Saga, you must mount the Saga middleware on the Store using applyMiddleware
at Function.sagaMiddleware.run 

这是有意义的,因为在将中间件应用于商店之前,我已经运行了中间件。但是,当我将它放在configureStore调用之后时,我得到:

代码语言:javascript
运行
复制
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

我以前也犯过这个错误,我不相信,因为它似乎只是出现在不同的问题上。我到底在做什么错事?

任何帮助都是感激的,谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-26 01:39:39

我在这里找到了答案:https://stackoverflow.com/a/69242812

代码语言:javascript
运行
复制
I had a similar issue; I fixed this by running npm install react-redux redux . Try it.

这显然与我的代码无关,而是我没有安装正确的软件包。希望有一天这能帮到别人!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72385675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档