javascript-使用React-Redux“ connect”时App类出错

尝试从react-redux使用connect()函数时,我收到以下错误:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

Check the render method of `App`.

这是应用程序:

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

这是聊天的相关代码结尾:

import { connect } from 'react-redux';


  ...


    const mapStateToProps = state => ({
  ...state
});
const mapDispatchToProps = dispatch => ({
  addMessage: () => dispatch(addMessage)
});

export default connect(
  mapStateToProps,mapDispatchToProps
)(Chat);

使用:“ export default Chat”代替connect时,它工作正常.

最佳答案
尝试这个:

const ConnectedChat = connect(
  mapStateToProps,mapDispatchToProps
)(Chat);

export default ConnectedChat;

或者,您可能希望将类定义重命名为ConnectedChat并反转名称,以便可以将其导入为“聊天”.

编辑:还要确保将聊天组件导入到App文件中,如果没有,请导入addMessage操作创建者.

相关文章

kindeditor4.x代码高亮功能默认使用的是prettify插件,prett...
这一篇我将介绍如何让kindeditor4.x整合SyntaxHighlighter代...
js如何实现弹出form提交表单?(图文+视频)
js怎么获取复选框选中的值
js如何实现倒计时跳转页面
如何用js控制图片放大缩小