react-redux 版本升级后出错

时间:2021-06-01 13:26:44

标签: javascript reactjs react-redux

我将 react-redux 版本升级到 v7.1.0 以支持钩子,但升级后,应用停止工作并引发以下错误。

Uncaught TypeError: Cannot read property 'subscribe' of undefined
    at new ConnectedRouter (ConnectedRouter.js:55)
    ... more lines here ...

这是从文件中提出的:ConnectedRouter.js from this line

54|       // Subscribe to store changes
55| ->    _this.unsubscribe = context.store.subscribe(function () {
56|         // Extract store's location

升级时我错过了什么吗?

以下是 package.json 中的一些版本:

"connected-react-router": "^4.5.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-redux": "^7.1.0",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"redux": "^3.7.2",
"redux-mock-store": "^1.5.1",
"redux-thunk": "^2.3.0",

这是我的 index.js 文件:

import thunk from 'redux-thunk';
// eslint-disable-next-line import/no-extraneous-dependencies
import { createBrowserHistory } from 'history';
import { applyMiddleware, compose, createStore, combineReducers } from 'redux';
import { connectRouter, routerMiddleware } from 'connected-react-router';

import reducers from './app/reducers';

const { NODE_ENV } = process.env;
export const history = createBrowserHistory();

export const store = createStore(
    connectRouter(history)(combineReducers(reducers)),
    compose(
        applyMiddleware(
            thunk,
            routerMiddleware(history),
        ),
        NODE_ENV === 'development'
            // eslint-disable-next-line no-underscore-dangle
            && window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__() : compose,
    ),
);

export const dispatchAction = (action) => (store.dispatch(action));

如果我需要在这里添加任何其他内容,请发表评论。

0 个答案:

没有答案