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.
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...
revert back to the working version v2.15.5 (for chrome)
- download https://github.com/zalmoxisus/redux-devtools-extension/releases/download/2.15.5/extension.zip
- extract the zip
- type
chrome://extensions
into the url and toggle ondeveloper mode
on thetop right
of the page. - the button
load unpacked
will appear. after clicking the button, select the extracted folder.
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
Source: stackoverflow.com
Related Query
- "Error: You may not call store.getState() while the reducer is executing."
- Error: "You may not call store.getState() while the reducer is executing." when changing language with react-i18next
- I am getting /bin/sh: [npm: not found error while executing the react image in Docker
- Store does not have a valid reducer while the reducer is empty
- What does the error "JSX element type '...' does not have any construct or call signatures" mean?
- Getting 404 error while call oAuth2 api in the browser
- snowpack Package "abstracts/variables" not found. Have you installed it? getting this error while running npm start
- Getting error while opening Google Drive Picker - The feature you requested is currently unavailable. Please try again later
- The code is working fine in codeSandbox, But showing error while doing in the IDE as "can't define property "email": Object is not extensible"
- You should not use <Link> outside a <Router> error while creating tutorial app with react-admin
- How do you get a button in DIV not call the <div> click event
- the same action when dispatched for the second time does not call the saga, while it does correctly in the first tie
- Using Redux Provider Store with Reactjs - error Store does not have a valid reducer
- Type Error : destroy is not a function in Reactjs while call api async function in useEffect hook
- TS18007: JSX expressions may not use the comma operator. Did you mean to write an array?
- You may need an additional loader to handle the result of these loaders error with CRA
- How do I resolve the operation not permitted error while attempting to install react?
- StencilJS error with React output target - You may need an additional loader to handle the result of these loaders
- Error: Actions must be plain objects. Instead, the actual type was: 'function'. You may need to add middleware to your store setup
- How to access the catch all route after ajax call failed while not changing URL with react-router
- Inject reducer for on demand component which was not in the store or combined reducers initially
- Reducer is not updating the store
- If you get an error in a function passed to setTimeout the component does not crash, why?
- Error : Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render
- Server Error ReferenceError: window is not defined This error happened while generating the page
- cryptic TypeScript error message when not returning the state from a reducer
- When react application is in production, while refreshing the same routes browser shows 404 error but not in localhost
- Redux tool kit error Error: Before running a Saga, you must mount the Saga middleware on the Store using applyMiddleware
- Redux-toolkit: Store does not have a valid reducer . Make sure the argument passed to combineReducers is an object whose values are reducers
- Could not able to view data while toggle the button in react. No error
More Query from same tag
- How to make array elements all separately clickable in table row in html
- How to pass props from one page using a Link(react-router) to a class component
- Recharts scatter chart shows the lowest x value in tooltip when chart is resized
- converting timestamp to fromnow() , moment showing 51 years fix value
- Typescript React empty function as defaultProps
- Add a State property to an Inline Style in React
- why form not taking input in the input field in react
- React state/child update not behaving as I expected it to
- ReactJS - I can't pass prop trought Route for a child component
- Why audio duration got changed
- React - Failing to give the same state to 2 elements with the same id (card and modal)
- Why image is not upload to server with react?
- Apache Error 404 in react app even after adding .htaccess
- run useEffect Hook only after condition is met
- Fetching data with React Hooks - Cannot read property 'map' of undefined
- Is it possible to set a server-side cookie in Next.js
- how add in this array all values? it's everytime create a new CLIENT array and push value to it
- NodeJS/MongoDB - field is being added only once?
- Redux-thunk - dispatch is not a function
- react-google-recaptcha allow CSP
- React router changes the url but not reload the component
- How to change an attribute value depend on the device used to view the page
- How to list a data inside another list using map and filter in React CLI (Comments List and Reply List)
- No change but re-rendered
- Fetch for refresh token not working (React.js)
- How to resize SVG to fill its container?
- ReactJS - based on input value - auto set the selection option
- Redux - Filter / Delete multiple items from array of objects. Items to be filtered given in another array
- Pass data to nested component in react.js
- React/Rebase/Firebase warning: Permission Denied - How do I add user authentication?