Reputation: 5411
This is how I create my store
import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import { routerMiddleware } from 'react-router-redux';
import rootReducer from '../reducers';
const debugware = [];
if (process.env.NODE_ENV !== 'production') {
const createLogger = require('redux-logger');
debugware.push(createLogger({
collapsed: true
}));
}
export default function configureStore(history, initialState) {
const store = createStore(
rootReducer,
initialState,
window.devToolsExtension ? window.devToolsExtension() : f => f,
applyMiddleware(thunkMiddleware, routerMiddleware(history), ...debugware),
);
if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../reducers', () => {
const nextRootReducer = require('../reducers/index').default;
store.replaceReducer(nextRootReducer);
});
}
return store;
}
But my app stop working and I can find why. Any suggestion please.
Upvotes: 3
Views: 3981
Reputation: 161
The DevTools' enhancer should be always the last in compose, so it will know about other middlewares and enhancers.
Additionally, in case you want to dispatch actions remotely, you should also add:
if (window.devToolsExtension) window.devToolsExtension.updateStore(store)
As indicated in troubleshooting.
Upvotes: 1
Reputation: 1844
You can try this:
import { createStore, applyMiddleware, compose } from 'redux';
const store = createStore(
rootReducer,
initialState,
compose(
applyMiddleware(thunkMiddleware, routerMiddleware(history), ...debugware),
window.devToolsExtension ? window.devToolsExtension() : f => f
)
);
Upvotes: 4