Quantcast
Channel: User totymedli - Stack Overflow
Viewing all articles
Browse latest Browse all 54

Answer by totymedli for "Error: You may not call store.getState() while the reducer is executing."

$
0
0

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),

Viewing all articles
Browse latest Browse all 54

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>