当我尝试更新任何反应组件时,我收到以下警告...
提供商不支持动态更改商店 . 您很可能会看到此错误,因为您已更新到Redux 2.x和React Redux 2.x,它们不再自动热重新加载Reducer . 有关迁移说明,请参阅https://github.com/reactjs/react-redux/releases/tag/v2.0.0 .
据我所知,我的代码看起来像指令,但我仍然得到警告 .
client.js
'use strict'
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { Router, browserHistory } from 'react-router';
import createStore from '../shared/store/createStore';
import routes from '../shared/routes';
const store = createStore(window.__app_data);
const history = browserHistory;
if (window.__isProduction === false) {
window.React = React; // Enable debugger
}
if (module.hot) {
module.hot.accept();
}
render (
<Provider store={store}>
<Router history={history} routes={routes} />
</Provider>,
document.getElementById('content')
)
configureStore.js
'use strict';
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import reducers from '../reducers';
import { selectSubreddit, fetchPosts } from '../actions'
export default function createReduxStore(initialState = {}) {
const store = createStore(reducers, initialState, applyMiddleware(thunk));
if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../reducers', () => {
const nextReducer = require('../reducers').default;
store.replaceReducer(nextReducer);
});
}
return store;
};
Server.js
import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import webpackConfig from '../../webpack.config.dev';
let compiler = webpack(webpackConfig);
app.use(webpackDevMiddleware(compiler, {
hot: true,
noInfo: true,
publicPath: webpackConfig.output.publicPath
}));
app.use(webpackHotMiddleware(compiler));
有什么我想念的吗?如果你想看到完整的src,这里是一个完整Github Repo的链接 .
[已编辑]添加了server.js和github链接 .
1 回答
找到了答案 . 需要进行多项更改 .
从 client.js 删除module.hot代码(热重新加载该文件导致Redux和React-Router警告 .
为要导出的React页面组件创建索引文件 .
将module.hot代码添加到新创建的索引文件中 .
将所有React组件更改为类 . const Page =()=>()不会通过热重新加载重新呈现 .
在进行这些更改后,一切都开始正常工作,我不再收到警告:-)