KELiON/redux-async-initial-state

Not compatible to redux 4.0.0

tsdevelopment opened this issue · 5 comments

The package can not be used with redux >= 4.0.0. Then I get the following error:

Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.

Yep, I just hit this too.

import { createBrowserHistory } from 'history'
import { applyMiddleware, combineReducers, createStore } from 'redux'
import { connectRouter, routerMiddleware } from 'connected-react-router'
import { composeWithDevTools } from 'redux-devtools-extension';
import * as asyncInitialState from 'redux-async-initial-state';

import userReducer from './user';

export const history = createBrowserHistory();

const rootReducer = combineReducers({
  user: userReducer,
  asyncInitialState: asyncInitialState.innerReducer,
});

//const reducer = asyncInitialState.outerReducer( rootReducer );

const initialState = {
  user: {}
};

const loadStore = ( getCurrentState ) => {
  return new Promise( resolve => {
    setTimeout( () => {
      resolve({
	...getCurrentState(),
	user: { id: 'yyy', name: 'aqpeeb' }
      });
    }, 500 );
  });
}

export const store = createStore(
  asyncInitialState.outerReducer( connectRouter(history)(rootReducer) ), // new root reducer with router state
  initialState,
  composeWithDevTools(
    applyMiddleware(
      routerMiddleware(history), // for dispatching history actions
      // ... other middlewares ...
      asyncInitialState.middleware(loadStore),
    ),
  ),
);

Unfortunately, the problem is still waiting for a solving

I backed off to redux 3.6.something and I am cool now.

Thanks @sshmyg for fixing this issue. You can try to install v0.3.0 that should be compatible with redux 4