“错误:在减速器执行时,您可能无法调用 store.getState()。”

IT技术 javascript reactjs redux react-redux
2021-03-27 12:00:38

我刚刚将功能齐全的 react-native 应用程序升级到 Redux v4,但现在出现以下错误:

错误:错误:错误:错误:在减速器执行时,您可能无法调用 store.getState()。减速器已经收到状态作为参数。从顶部减速器传递它而不是从商店读取它。

我怀疑问题在于我在其他组件中有许多组件,每个组件都有自己的组件connect(mapStateToProps, mapDispatchToProps)(Component),我认为这不是实现它的正确方法,尽管我不确定正确的方法。

任何方向都非常感谢!

堆栈跟踪:

    This error is located at:
    in Connect(SideBarApp) (at SceneView.js:9)
    in SceneView (at createTabNavigator.js:10)
    in RCTView (at View.js:43)
    in RCTView (at View.js:43)
    in ResourceSavingScene (at createBottomTabNavigator.js:86)
    in RCTView (at View.js:43)
    in RCTView (at View.js:43)
    in TabNavigationView (at createTabNavigator.js:127)
    in NavigationView (at createNavigator.js:59)
    in Navigator (at createNavigationContainer.js:376)
    in NavigationContainer (at SceneView.js:9)
    in SceneView (at SwitchView.js:12)
    in SwitchView (at createNavigator.js:59)
    in Navigator (at createNavigationContainer.js:376)
    in NavigationContainer (at AppNavigator.js:36)
    in App (created by Connect(App))
    in Connect(App) (at index.ios.js:23)
    in Provider (at index.ios.js:22)
    in TheNewsApp (at renderApplication.js:32)
    in RCTView (at View.js:43)
    in RCTView (at View.js:43)
    in AppContainer (at renderApplication.js:31)

This error is located at:
    in NavigationContainer (at SceneView.js:9)
    in SceneView (at SwitchView.js:12)
    in SwitchView (at createNavigator.js:59)
    in Navigator (at createNavigationContainer.js:376)
    in NavigationContainer (at AppNavigator.js:36)
    in App (created by Connect(App))
    in Connect(App) (at index.ios.js:23)
    in Provider (at index.ios.js:22)
    in TheNewsApp (at renderApplication.js:32)
    in RCTView (at View.js:43)
    in RCTView (at View.js:43)
    in AppContainer (at renderApplication.js:31)

This error is located at:
    in NavigationContainer (at AppNavigator.js:36)
    in App (created by Connect(App))
    in Connect(App) (at index.ios.js:23)
    in Provider (at index.ios.js:22)
    in TheNewsApp (at renderApplication.js:32)
    in RCTView (at View.js:43)
    in RCTView (at View.js:43)
    in AppContainer (at renderApplication.js:31)
getState@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:79579:24
runComponentSelector@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:78896:56
initSelector@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:79019:28
Connect(SideBarApp)@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:78969:29
constructClassInstance@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:20826:32
updateClassComponent@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22393:35
performUnitOfWork@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:24922:27
workLoop@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:24955:47
renderRoot@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:24988:21
performWorkOnRoot@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:25549:23
performWork@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:25481:30
performSyncWork@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:25456:20
requestWork@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:25362:26
scheduleWork@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:25224:28
enqueueSetState@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:20681:23
setState@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:2380:37
dispatch@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:80901:27
navigate@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:80517:24
nav@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:80470:44
combination@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:79810:38
dispatch@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:79628:38
setLoginStatus@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:112247:19
http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:112199:44
tryCallOne@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:8818:16
http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:8919:27
_callTimer@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:8162:17
_callImmediatesPass@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:8198:19
callImmediates@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:8417:33
__callImmediates@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7741:32
http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7580:34
__guard@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7721:15
flushedQueue@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7579:21
flushedQueue@[native code]
invokeCallbackAndReturnFlushedQueue@[native code]
6个回答

redux-devtools-extension新 v2.16.0 版本的一个问题

我们等待修复时,这里有一些解决方法......

  1. 恢复到工作版本 v2.15.5(适用于 Chrome

  2. 或者只是暂时禁用您的redux-devtool 扩展

    • 在浏览器级别或通过您的代码(您在其中创建 redux 存储)

仅供参考:这不能解决 OP 的问题,但可以解决开发人员从 18 年 11 月 27 日开始收到以下错误消息的问题。

Error: You may not call store.getState() while the reducer is executing. The reducer has already received the state as an argument. Pass it down from the top reducer instead of reading it from the store.


更新

v2.16.2已经发布

对于之前禁用该扩展的用户,只需重新启用它并将您的 redux 开发工具从 2.16.0更新到 2.16.2更新 Redux 开发工具

花了将近一个小时才找到这个问题。恢复到 v2.15.5。现在一切正常。
2021-05-23 12:00:38
@bitstrider 当然,它没有解决 OP 的问题。但它似乎确实帮助了很多人解决了当前的情况。对于那些想知道这个问题的状态的人,这里是为它发布github 问题
2021-05-26 12:00:38
这个清晨让我免了很多头痛
2021-06-06 12:00:38
一个小时前,每个使用redux-devtools-extension 的人都遇到了这个问题的很好的解决方法,但并没有真正解决 OP 的问题,这个问题在这个有漏洞的 v2.16.0 版本发布之前被问到了……只是说
2021-06-14 12:00:38
已发布修复此问题的 redux-devtools-extension 2.16.1 版
2021-06-18 12:00:38

就我而言,我必须删除composeWithDevTools - chrome 插件

import { createStore, combineReducers, applyMiddleware } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import thunk from 'redux-thunk';

// const enhancer = composeWithDevTools(applyMiddleware(thunk))
const enhancer = applyMiddleware(thunk)

const store = createStore(reducers, enhancer);
谢谢。这对我有用。禁用 Redux Chrome 扩展也有效。这只会发生在今天。想知道为什么...
2021-05-24 12:00:38
@ImanMahmoudinasab - 我使用的是 Chrome 版本 55.x(虽然最新版本是 70.x),但仍然面临同样的问题。卸载 Redux DevTools (v 2.16.0) 后,我的应用程序按照 Viet Le 的建议运行良好。
2021-06-03 12:00:38
同样在这里@JacobGoh,面临同样的问题,以前从未遇到过。Chrome 网上商店表示该扩展程序已于 11 月 27 日更新,也许他们破坏了某些东西。
2021-06-18 12:00:38

在我的项目中。有一天,这个问题突然冒出来了。

我的解决方案:禁用 Chrome 扩展程序 - Redux Devtools。 然后一切恢复正常。

所以对于这种错误,你应该在几个浏览器中测试以找到问题。

禁用 chrome 扩展或composeWithDevTool从您的代码中删除将作为快速修复。但是我们都知道我们需要扩展来跟踪我们的应用程序状态并正确管理它。所以我今天创建了一个问题,希望能够支持,redux 团队的某个人会回复我们。

或者,如果您正在寻找临时解决方法(适用于 chrome),您可以下载https://github.com/zalmoxisus/redux-devtools-extension/releases/download/2.15.5/extension.zip,然后将其解压缩到一些文件夹。

键入 chrome://extensions 并从左上角打开开发人员模式,然后单击“加载未打包”并选择解压缩的文件夹以供使用。

问题:https : //github.com/reduxjs/redux-devtools/issues/413

对我有用的解决方案

禁用Redux Dev tools的 Chrome 扩展从您的代码中删除记录器

更新:将您的 redux 开发工具从 2.16.0更新到 2.16.1 更新 Redux 开发工具