score:1

i had this problem on chrome. downgrading my version of redux from 4.0.2 to 3.7.2 fixed it for me.

npm uninstall redux

npm install redux@3.7.2

score:1

note: i am using saga

in my case i had added a navigation code inside a reducer.

    sendotpsuccess: (state, action) => {
      state.wip = false;

      rootnavigation.navigate('loginotpscreen');
    },

in the beginning it was working but when i used/accessed state inside the called new screen

import { usedispatch, useselector } from "react-redux";
import * as sessionactions from "../../models/session";

const loginotp: () => node = (props) => {
  const session = useselector(sessionactions.selectsession);
  const dispatch = usedispatch();
  ...

the error popped up.

“error: you may not call store.getstate() while the reducer is executing.”

cause

reducer is supposed to be a pure function. it should accept a payload and modify state and nothing else. something else is considered as a side-effect.

i my case i loaded a new component which also consumes state data and the state modification is not yet completed. this is causing the issue.

solution

i simply moved the navigation to respective saga

// worker saga:
function* sendotpsaga({ payload }) {
  const { phonenumber } = payload;
  try {
    const response = yield call(api.sendotp, { phonenumber });
    if (response.status == 200) {
      yield put(sessionactions.sendotpsuccess(response.data));
      rootnavigation.navigate('loginotpscreen'); // <---- here
    ...

score:2

i had the same error with a pwa build with polymer 3. the store.js also tried to use the redux dev tools which i had to deactivate:

...
// 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))
);
...

score:2

this is what i did: just commented the line for chrome redux devtools extension from my store.js file.

....

 const store = createstore(
  rootreducer,
  initialstate,
  compose(
    applymiddleware(...middleware)
   ///this line--> window.__redux_devtools_extension__ && window.__redux_devtools_extension__() 
  )
);

....

and the issue is just begun an hour ago. as we all know the extension is very handy during development, so let us wait for the real fix from the authorities.

score:2

should be fixed now. update your redux dev tools from 2.16.0 to 2.16.1

https://github.com/zalmoxisus/redux-devtools-extension/issues/588#issuecomment-442396540

score:3

in my case the issue was not related to dev extension. i've encountered this error while working with deep-linking - was updating route query inside reducer. wrapping logic related to manipulating url inside settimeout fixed the error.

score:5

disabling chrome extension or removing composewithdevtool from your code will work as a quick fix. but we all know that we need the extension in order to track our application state and manage it properly. so i created an issue today please support hopefully, someone from the redux team will get back to us.

or if you are looking for a temporary workaround(for chrome), you can download https://github.com/zalmoxisus/redux-devtools-extension/releases/download/2.15.5/extension.zip and then extract it to some folder.

type chrome://extensions and turn on developer mode from top left and then click on load unpacked and select the extracted folder for use.

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

score:5

solution that work for me

disable the chrome extension of redux dev tools. or remove logger from your code.

update: update your redux dev tools from 2.16.0 to 2.16.1 update redux dev tools.

score:5

tl;dr

make sure you don't have any code that causes side effects in your reducers!

pure reducers

redux reducers need to be pure. this means they shouldn't have side effects. side effects should go to thunks or sagas. in my case a reducer looked like this:

case redirect_on_event: {
  history.push('/some-route'); // side effect: redirection
  return {
    ...state,
    path: action.payload.path,
  };
}

the history.push('/some-route'); part messed up state management. removing it from the reducer and placing it to a saga that gets called on the same action type fixed the issue:

function redirecttosomeroute() {
  history.push('/some-route');
}

takeevery(redirect_on_event, redirecttosomeroute),

score:11

in my project. this issue just popup from nowhere one day.

my solution: disable the chrome extension - redux devtools. then everything is back to normal.

so with this kind of error, you should test in several browser to find the problem.

score:24

in my case, i have to remove composewithdevtools - a plugin for 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);

score:195

it's an issue with the new v2.16.0 release of redux-devtools-extension.

here's a couple of workaround while we wait for the fix...

  1. revert back to the working version v2.15.5 (for chrome)

  2. or just simply disable your redux-devtool extension for now.

    • either on the browser level or through your code(where you create the redux store)

fyi: this does not solve the op's question but does solve the issue where developers are receiving the below error message starting 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.


update

v2.16.2 has been released

for those who had previously disabled the extension, just re-enable it and update your redux dev tools from 2.16.0 to 2.16.2 update redux dev tools


Related Query

More Query from same tag