“错误:减速器执行时,您不得调用store.getState()。”


71

我刚刚将功能齐全的本机应用程序升级到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]

1
您可以添加堆栈跟踪吗?这将帮助我们给出更准确的答案。
泰国

您能否分享您实际调用的代码片段store.getState()
西尔万

1
我不叫store.getState()
bbrodsky '18

我们可以在SceneView.js:9和createTabNavigator.js:10看到正在发生的事情,这很有用
Ben Smith,

这些都不是我的代码。我不确定SceneView的来源,但是createTabNavigator来自react-navigation github.com/react-navigation/react-navigation
bbrodsky '18

Answers:


191

这是redux-devtools-extension新v2.16.0版本的问题。

这是我们等待修复的几种解决方法...

  1. 还原回工作版本v2.15.5(适用于Chrome

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

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

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

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开发工具


8
尼斯的办法解决这个问题,它的字面只使用弹出一个小时前为大家终极版-devtools扩展,但并没有真正的地址OP的问题,这是问路这种窃听v2.16.0发布之前...只是说

1
@bitstrider当然,它不能解决OP的问题。但这似乎可以帮助很多人摆脱目前的困境。对于那些想知道此问题状态的人,这里是为此发布的github问题
维克多·勒

3
今天清晨为我省去了很多头痛
ABEL MASILA

1
花了将近一个小时才找到这个问题。恢复为v2.15.5。现在一切正常。
domino_katrino

2
终极版-devtools扩展,修复这个问题的2.16.1版本,已经发布
帕特里克·洪特

24

就我而言,我必须删除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);

6
谢谢。这对我有用。禁用Redux Chrome Extension也可以。仅从今天起发生这种情况。不知道为什么...
Jacob Goh

2
@JacobGoh在这里也一样,面临相同的问题,以前从未遇到过。Chrome网上商店说,扩展程序已于11月27日更新,也许他们出了点问题。
Artem Ibragimov


@ImanMahmoudinasab-我使用的Chrome版本为55.x(尽管最新版本为70.x),仍然遇到相同的问题。卸载Redux DevTools(v 2.16.0)后,我的应用程序运行正常,如Viet Le所建议。
domino_katrino

11

在我的项目中。这个问题只是一天从无处弹出。

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

因此,遇到这种错误,您应该在多个浏览器中进行测试以发现问题。


5

禁用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



2

使用聚合物3进行PWA构建时,我遇到了相同的错误。store.js还尝试使用必须停用的redux开发工具:

...
// Sets up a Chrome extension for time travel debugging.
// See https://github.com/zalmoxisus/redux-devtools-extension for more information.
//const devCompose = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const devCompose =  compose;

// Initializes the Redux store with a lazyReducerEnhancer (so that you can
// lazily add reducers after the store has been created) and redux-thunk (so
// that you can dispatch async actions). See the "Redux and state management"
// section of the wiki for more details:
// https://github.com/Polymer/pwa-starter-kit/wiki/4.-Redux-and-state-management
export const store = createStore(
  state => state,
  devCompose(
    lazyReducerEnhancer(combineReducers),
    applyMiddleware(thunk))
);
...

2

这就是我的工作:刚刚从store.js文件中注释了Chrome Redux Devtools Extension行。

....

 const store = createStore(
  rootReducer,
  initialState,
  compose(
    applyMiddleware(...middleware)
   ///This line--> window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() 
  )
);

....

这个问题是一个小时前才开始的。众所周知,扩展在开发过程中非常方便,因此让我们等待权威机构的实际修复。



1

就我而言,该问题与开发人员扩展无关。我在使用深层链接时遇到了此错误-在reducer中更新路由查询。与在settimeout内部处理url相关的包装逻辑可修复该错误。


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.