Redux 热更新 不可用
// index.js
import React from 'react'
import { Provider } from 'react-redux'
import { render } from 'react-dom'
import configureStore from './configureStore'
import App from './app'
import './index.less'
const rootEl = document.getElementById('app')
const store = configureStore()
render(
<Provider store={store}>
<App />
</Provider>,
rootEl,
)
// configureStore.js
export default function configureStore(initialState) {
const middleware = []
const store = createStore(
rootReducer,
initialState,
compose(
applyMiddleware(...middleware),
process.env.NODE_ENV !== 'production' &&
window.__REDUX_DEVTOOLS_EXTENSION__ &&
window.__REDUX_DEVTOOLS_EXTENSION__(),
),
)
if (module.hot) {
module.hot.accept('./reducers', () => {
const nextRootReducer = require('./reducers/index').default
store.replaceReducer(nextRootReducer)
})
} else {
console.log('not hot')
}
return store
}
目录结构
以解决问题, 热更新 更新了index.js 导致redux 热更新失败