尝试从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时,它工作正常.
最佳答案
原文链接:https://www.f2er.com/js/531299.html