这是我创建商店的方式
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;
}
但我的应用程序停止工作,我可以找到原因。有任何建议请。
答案 0 :(得分:4)
你可以试试这个:
import { createStore, applyMiddleware, compose } from 'redux';
const store = createStore(
rootReducer,
initialState,
compose(
applyMiddleware(thunkMiddleware, routerMiddleware(history), ...debugware),
window.devToolsExtension ? window.devToolsExtension() : f => f
)
);
答案 1 :(得分:1)
DevTools的增强器应该始终是最后的组合,因此它将了解其他中间件和增强器。
此外,如果您想远程调度操作,还应添加:
if (window.devToolsExtension) window.devToolsExtension.updateStore(store)
如troubleshooting所述。