简单的反应冗余连接函数中的错误



我在尝试使用 react-redux 的"连接"函数时收到以下错误:

"TypeError: react__WEBPACK_IMPORTED_MODULE_4___default.a.memo is not a function"

还有以下详细信息:

wrapWithConnect
C:/.../node_modules/react-redux/es/components/connectAdvanced.js:325
  322 | } // If we're in "pure" mode, ensure our wrapper component only re-renders when incoming props have changed.
  323 | 
  324 | 
> 325 | var Connect = pure ? React.memo(ConnectFunction) : ConnectFunction;
  326 | Connect.WrappedComponent = WrappedComponent;
  327 | Connect.displayName = displayName;
  328 | 

还没有找到与我的问题相关的任何对此错误的引用......

这是我在">

聊天.js"类末尾与"连接"一起使用的代码:

import { connect } from 'react-redux';

  ...

const mapStateToProps = state => ({
  ...state
});
const mapDispatchToProps = dispatch => ({
  addMessage: () => dispatch(addMessage)
});
export default connect(
  mapStateToProps,
  mapDispatchToProps
)(Chat);

此代码用于名为"聊天.js"的类中。当使用"导出默认聊天"而不使用redux"连接"时,一切都很好。

我将提供商标签用作"App.js"中聊天组件的包装器:

import { Provider } from 'react-redux';
const App = class extends React.PureComponent {
  render() {
    const { title } = this.context;
    return (
      <div className="center-screen">
        {title}
        <Provider store={configureStore()}>
          <Chatroom />
        </Provider>
      </div>
    );
  }
};

行动:

export function addMessage(text) {
  return { type: 'addMessage', text };
}

还原剂:

export default (state, action) => {
  switch (action.type) {
    case 'addMessage':
      return {
        text: action.text
      };
    default:
      return state;
  }
};

共享 webpack 文件 too.so 我可以检查 webpack 设置中是否存在任何问题

最新更新