Я модернизировал реаги-редукс, чтобы использовать редукс с крючками.
Итак, я попытался перейти на реакцию-избыточность с версии 5 до последней версии (^ 7.1.3). Но затем я получаю эту ошибку:
TypeError: Cannot read property 'subscribe' of undefined
new ConnectedRouter
node_modules/connected-react-router/lib/ConnectedRouter.js:102
99 |
100 | _this.inTimeTravelling = false; // Subscribe to store changes
101 |
> 102 | _this.unsubscribe = context.store.subscribe(function () {
| ^ 103 | // Extract store's location
104 | var _toJS = toJS(getIn(context.store.getState(), ['router', 'location'])),
105 | pathnameInStore = _toJS.pathname,
Я также пытался обновить свой подключенный реагирующий маршрутизатор, но затем получаю еще одну ошибку.
Версии некоторых из моих пакетов:
"react": "^16.8.6",
"connected-react-router": "4.5.0",
"react-redux": "^7.1.3",
"react-router": "4.3.1",
"react-router-dom": "4.3.1",
"react-router-redux": "^4.0.8",
"redux": "^4.0.4",
"redux-thunk": "^2.3.0",
и вот мой index.js
:
import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { ConnectedRouter } from "connected-react-router";
import store, { history } from "store";
import "styles/layout.scss";
import App from "App";
import * as serviceWorker from "./serviceWorker";
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<div>
<App />
</div>
</ConnectedRouter>
</Provider>,
document.getElementById("root")
);
Мой store.js
import { createStore, applyMiddleware, compose } from 'redux'
import { connectRouter, routerMiddleware } from 'connected-react-router'
import thunk from 'redux-thunk'
import { createBrowserHistory as createHistory } from 'history'
import rootReducer from 'Store/Reducers/rootReducer'
export const history = createHistory()
const initialState = {}
const enhancers = []
const middleware = [thunk, routerMiddleware(history)]
if (process.env.NODE_ENV === 'development') {
const devToolsExtension = window.__REDUX_DEVTOOLS_EXTENSION__
if (typeof devToolsExtension === 'function') {
enhancers.push(devToolsExtension())
}
}
const composedEnhancers = compose(
applyMiddleware(...middleware),
...enhancers
)
export default createStore(
connectRouter(history)(rootReducer),
initialState,
composedEnhancers
)