关于网友提出的“ does not support changing `store`”问题疑问,本网通过在网上对“ does not support changing `store`”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: does not support changing `store`
描述: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(
,
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
}
目录结构

解决方案1:store
被修改了?
给运行正常的代码:
store.js
import {createStore, applyMiddleware, compose} from 'redux';
import thunkMiddleware from 'redux-thunk';
import createLogger from 'redux-logger';
import YourReducer from '../reducers/YourReducer.js'; //import your reducer
let createStoreWithMiddleware = null;
if(process.env.NODE_ENV === 'production') {
createStoreWithMiddleware = compose(applyMiddleware(
thunkMiddleware
))(createStore);
} else {
createStoreWithMiddleware = compose(applyMiddleware(
thunkMiddleware,
createLogger()
), window.devToolsExtension ? window.devToolsExtension() : f => f)(createStore);
}
export default (initState) => {
return createStoreWithMiddleware(YourReducer, initState);
}
index.js
import {Provider} from 'react-redux';
import store from './stores/store.js';
//...
以上介绍了“ does not support changing `store`”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/4536212.html