Javascript 未捕获类型错误:无法设置函数设置(props)的属性propTypes

Javascript 未捕获类型错误:无法设置函数设置(props)的属性propTypes,javascript,reactjs,react-redux,Javascript,Reactjs,React Redux,道具类型在正常react组件中工作正常,但在Redux连接组件中失败 错误详细信息 未捕获类型错误:无法设置函数设置(props)的属性propTypes 完整的错误详细信息 未捕获类型错误:无法设置函数设置(props)的属性propTypes{ _classCallCheck(此,设置) var\u this=\u possibleConstructorReturn(thi……}只有一个getter 在Object.eval(Settings.js?384b:533) 评估时(Setting

道具类型在正常react组件中工作正常,但在Redux连接组件中失败

错误详细信息

未捕获类型错误:无法设置函数设置(props)的属性propTypes

完整的错误详细信息

未捕获类型错误:无法设置函数设置(props)的属性propTypes{ _classCallCheck(此,设置)

var\u this=\u possibleConstructorReturn(thi……}只有一个getter
在Object.eval(Settings.js?384b:533)
评估时(Settings.js:509)
at Object../src/Navigation/Components/Settings.js(main.b2f70c3c5e2d43b8884a.js?b2f70c3c5c5e2d43b8884a:14403)
at网页需要(main.b2f70c3c5e2d43b8884a.js?b2f70c3c5c5e2d43b8884a:725)
在fn(main.b2f70c3c5e2d43b8884a.js?b2f70c3c5e2d43b8884a:102)
评估时(routes.js?5665:15)
at Object../src/routes.js(main.b2f70c3c5e2d43b8884a.js?b2f70c3c5e2d43b8884a:14763)
at网页需要(main.b2f70c3c5e2d43b8884a.js?b2f70c3c5c5e2d43b8884a:725)
在fn(main.b2f70c3c5e2d43b8884a.js?b2f70c3c5e2d43b8884a:102)
评估时(索引js?b635:2)
我使用的是道具类型v15、react v16、react redux v3库

Settings.js组件:

import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import React, { Component } from 'react';

class Settings extends Component {
constructor(props) {
    super(props);
}

static get propTypes() {
    return {
      loginId:React.PropTypes.string,
      loading: React.PropTypes.bool,  
      updateEmail: React.PropTypes.func
    }
  }

render(){
   return(
      <div>{this.props.text}</div>
   )
  }
}

function mapStateToProps(state) {
   let text = "Hello Settings";
   return {
      text
   }
}

Settings.propTypes = {
    loginId: PropTypes.string,
    loading: PropTypes.bool
  }

export default connect(mapStateToProps, null)(Settings);
从“道具类型”导入道具类型;
从'react redux'导入{connect};
从“React”导入React,{Component};
类设置扩展组件{
建造师(道具){
超级(道具);
}
静态get propTypes(){
返回{
loginId:React.PropTypes.string,
加载:React.PropTypes.bool,
updateMail:React.PropTypes.func
}
}
render(){
返回(
{this.props.text}
)
}
}
函数MapStateTops(状态){
让text=“Hello Settings”;
返回{
文本
}
}
Settings.propTypes={
loginId:PropTypes.string,
加载:PropTypes.bool
}
导出默认连接(MapStateTops,null)(设置);

mapStateToProps用于将变量从redux存储发送到react组件

但你只是用它来设置道具

但是,根据Bartek的评论,您可以尝试以下方法:

const mapStateToProps = state => {
    return {
        text: "hello settings"
    }
}
您应该使用MapStateTops的方式如下:

const mapStateToProps = state => {
    return {
        text: state.text
    }
}

也许,这是因为mapStateToProps?您在该函数中返回undefined。很抱歉,这是我的错误。即使在MapStateTops中返回文本,它也会失败。更新了我的代码。很抱歉,这是我的错误。我没有删除旧的静态get propTypes,这就是为什么它失败的原因。在删除静态get propTypes后,问题得到了解决。很抱歉,提供了丁少了一些信息。谢谢你的时间。谢谢乔伊。我尝试了你的解决方案,但它给了我同样的错误哦,看起来你的类中缺少了一个右括号
}
很抱歉,我手动键入了代码。我对正确的组件有同样的问题。我添加了完整的错误详细信息。你能检查一下你是否包装了Ap吗p在a中?我所能想到的是,您没有将
connect
用于其预期目的。为什么不将该文本消息设置为初始状态?
const mapStateToProps = state => {
    return {
        text: state.text
    }
}