![](/img/trans.png)
[英]Redux and React. Uncaught TypeError: Cannot read property 'dispatch' of undefined
[英]React Redux Cannot read property 'dispatch' of undefined
我对我的应用程序包进行了一些更新,例如:
"react-redux": "^5.0.6" => "^6.0.1",
"redux": "^3.7.2" => "^4.0.1",
"redux-saga": "^0.16.0" => "^1.0.1"
但我得到了错误
无法读取未定义的属性“调度”
这是我的 index.js:
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import createSagaMiddleware from 'redux-saga';
import { Provider } from 'react-redux';
import { Route } from 'react-router-dom';
import { ConnectedRouter, routerMiddleware } from 'react-router-redux';
import createHistory from 'history/createHashHistory';
import { writeSaga } from './sagas/writeSaga';
import { readSaga } from './sagas/readSaga';
import App from './App';
import reducers from './reducers';
const history = createHistory();
const sagaMiddleware = createSagaMiddleware();
const middlewares = [routerMiddleware(history), thunk, sagaMiddleware];
const store = createStore(reducers, applyMiddleware(...middlewares));
export default function* rootSaga() {
yield [
writeSaga(),
readSaga(),
]
};
sagaMiddleware.run(rootSaga);
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<Route path="/" component={App} />
</ConnectedRouter>
</Provider>,
document.getElementById('app-container')
);
在这里我得到错误(react-router-redux ConnectedRouter.js):
有什么建议?
更新 1添加/删除包,我知道导致该问题的包是“react-redux”的升级(5.0.6 => 6.0.1)
更新 2看着 react-redux 的重大变化,我能够理解问题是我如何通过商店(重大变化)。
我将代码更改为:
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history} store={store}>
<Route path="/" component={App} store={store} />
</ConnectedRouter>
</Provider>,
document.getElementById('app-container')
);
它有效!
但我知道这不是正确的方法……也许它对正确的解决方案很有用。
为什么这不是另一个问题的重复:我有相同的配置来索引,我检查了它并且我确定我正在使用 react-router-redux。 在我导出的每个页面中
export default connect(mapDispatchToProps)(Home);
更改自:
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<Route path="/" component={App} />
</ConnectedRouter>
</Provider>,
document.getElementById('app-container')
);
到:
ReactDOM.render(
<Provider>
<ConnectedRouter history={history} store={store}>
<Route path="/" component={App} />
</ConnectedRouter>
</Provider>,
document.getElementById('app-container')
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.