下一个 redux wrapper 出现 Cannot read 属性 'getState' of undefined 错误

Next redux wrapper arise error of Cannot read property 'getState' of undefined

在这个项目中,我使用了下一个 js 库和 redux,我也使用了下一个 redux 包装器我做了下一个 redux 包装器文档中提到的所有事情,但是它在这里工作不正常,它出现了 getState of undefined 错误正如我在上图中显示的那样。所以在这里我调试了所有的代码,但我找不到这个错误发生的地方。 我在下面列出了我在反应 js 文件中完成的代码。

_app.js

import React from "react";
import App from "next/app";
import { Provider } from "react-redux";
import withRedux from "next-redux-wrapper";
import makeStore from ".././src/config/store";

class ConsoleApp extends App {
  /**
   * Render View
   */
  render() {
    const { Component, pageProps, store } = this.props;
    return (
      <Provider store={store}>
        <Component {...pageProps} />
      </Provider>
    );
  }
}

export default withRedux(makeStore)(ConsoleApp);

root-reducer.js

/**
 * Import Dependencies
 */
import { combineReducers } from "redux-immutable";

/**
 * Import Reducers
 * All Reducers used in the App must be declared here!
 */
import GraphicReducer from "../modules/Graphics/reducer";
import UserReducer from "../modules/User/reducer";
/**
 * Combine the Reducers
 */
const reducers = combineReducers({
  graphics: GraphicReducer,
  user: UserReducer
});

/**
 * Export the combined Reducers
 */
export default reducers;

store.js

import { createStore, applyMiddleware } from "redux";
import { composeWithDevTools } from "redux-devtools-extension";
import reducers from "./root-reducer";
import thunk from "redux-thunk";
/**
 * Prepare the Redux Store
 */

const composedMiddlewares = applyMiddleware(thunk);

const storeEnhancers = composeWithDevTools({
  name: "React-node-test"
})(composedMiddlewares);

const makeStore = () => {
  createStore(reducers, storeEnhancers);
};

export default makeStore;

请使用下面的代码片段,因为您忘记了 return createStore(reducers, storeEnhancers);

const makeStore = () => {
  return createStore(reducers, storeEnhancers);
};